-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_test.go
44 lines (33 loc) · 866 Bytes
/
global_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
44
package mathu_test
import (
"math"
"testing"
"github.com/clavoie/mathu"
)
func TestZero(t *testing.T) {
f := 1.0
fe := f + mathu.Epsilon64
if fe <= f || fe >= 2.0 {
t.Fatal(f, mathu.Epsilon64, fe)
}
nf := -1.0
nfe := nf + mathu.NegEpsilon64
if nfe >= nf || nfe <= -2.0 {
t.Fatal(nf, mathu.NegEpsilon64, nfe)
}
if mathu.Zero(f) {
t.Fatal("Should not be zero", f)
}
if mathu.Zero(mathu.Epsilon64) == false {
t.Fatal("Epsilon should be zero", mathu.Epsilon64)
}
if mathu.Zero(nf) {
t.Fatal("Should not be zero", nf)
}
if mathu.Zero(mathu.NegEpsilon64) == false {
t.Fatal("Should be zero", mathu.NegEpsilon64)
}
if mathu.Zero(math.SmallestNonzeroFloat64) == false {
t.Fatal("Should be zero", math.SmallestNonzeroFloat64, math.SmallestNonzeroFloat64 <= mathu.Epsilon64, mathu.NegEpsilon64 <= math.SmallestNonzeroFloat64)
}
}