-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp128_test.go
More file actions
98 lines (86 loc) · 2.23 KB
/
Copy pathexp128_test.go
File metadata and controls
98 lines (86 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package floats
import (
"math"
"runtime"
"testing"
)
func TestFloat128_Exp(t *testing.T) {
tests := []struct {
x Float128
want string
}{
{exact128(-1), "0.3678794411714423215955237701614608674458111310317678345078368016974614957449"},
{exact128(0), "1"},
{exact128(1), "2.71828182845904523536028747135266249775724709369995957496696762772407663035355"},
{exact128(2), "7.38905609893065022723042746057500781318031557055184732408712782252257379607906"},
{exact128(3), "20.085536923187667740928529654581717896987907838554150144378934229698845878092"},
{exact128(4), "54.5981500331442390781102612028608784027907370386140687258265939585536620999359"},
}
for _, tt := range tests {
got := tt.x.Exp()
if !close128(got, tt.want) {
t.Errorf("Exp(%v) = %v; want %v", tt.x, got, tt.want)
}
}
strictTests := []struct {
x Float128
want Float128
}{
// special cases
{exact128(math.Inf(1)), exact128(math.Inf(1))},
{exact128(math.Inf(-1)), exact128(0)},
{exact128(math.NaN()), exact128(math.NaN())},
}
for _, tt := range strictTests {
got := tt.x.Exp()
if !eq128(got, tt.want) {
t.Errorf("Exp(%v) = %v; want %v", tt.x, got, tt.want)
}
}
}
func TestFloat128_Exp2(t *testing.T) {
tests := []struct {
x Float128
want string
}{
{exact128(-1), "0.5"},
{exact128(0), "1"},
{exact128(1), "2"},
{exact128(1.5), "2.828427124746190097603377448419396157139343750753896146353359822541"},
}
for _, tt := range tests {
got := tt.x.Exp2()
if !close128(got, tt.want) {
t.Errorf("Exp2(%v) = %v; want %v", tt.x, got, tt.want)
}
}
strictTests := []struct {
x Float128
want Float128
}{
{exact128(16385), exact128(math.Inf(1))},
{exact128(-16496), exact128(0)},
// special cases
{exact128(math.Inf(1)), exact128(math.Inf(1))},
{exact128(math.Inf(-1)), exact128(0)},
{exact128(math.NaN()), exact128(math.NaN())},
}
for _, tt := range strictTests {
got := tt.x.Exp2()
if !eq128(got, tt.want) {
t.Errorf("Exp2(%v) = %v; want %v", tt.x, got, tt.want)
}
}
}
func BenchmarkFloat128_Exp(b *testing.B) {
x := exact128(1.5)
for b.Loop() {
runtime.KeepAlive(x.Exp())
}
}
func BenchmarkFloat128_Exp2(b *testing.B) {
x := exact128(1.5)
for b.Loop() {
runtime.KeepAlive(x.Exp2())
}
}