-
Notifications
You must be signed in to change notification settings - Fork 1
/
exp_test.go
43 lines (40 loc) · 1.15 KB
/
exp_test.go
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
package fixed
import (
"math"
"testing"
)
func TestRange_NegExp(t *testing.T) {
maxEpow := fixed56(34)
acc := accuracy{Epsilon: float56(1 << max64(int64(fracBits-46), 2))}
step := maxEpow / 10000
t.Logf("max possible exponent argument is %g, step %g\n", float56(maxEpow), float56(step))
for i := -maxEpow; i <= 0; i += step {
a := randomFixed(i)
y := exp56(a)
got := y.float()
want := math.Exp(float56(a))
if ok := acc.update(y, want); !ok {
t.Errorf("exp(%v) => got %v|%v, want %v|%v", float56(a), y, got, From(want), want)
t.FailNow()
}
}
t.Log(acc)
}
func TestRange_Exp(t *testing.T) {
maxEpow := fixed56(33) // fixed56(88)
acc := accuracy{}
step := maxEpow / 1000
t.Logf("max possible exponent argument is %g, step %g\n", float56(maxEpow), float56(step))
for i := fixed56(0); i < maxEpow; i += step {
a := randomFixed(i)
y := exp56(a)
got := y.float()
want := math.Exp(float56(a))
acc.Epsilon = float56(1 << min64(max64(int64(y.bitlen()-24), 2), 62))
if ok := acc.update(y, want); !ok {
t.Errorf("exp(%v) => got %v|%v, want %v|%v, eps: %v", float56(a), y, got, From(want), want, acc.Epsilon)
t.FailNow()
}
}
t.Log(acc)
}