-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_util.go
35 lines (28 loc) · 987 Bytes
/
test_util.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
package godist
import (
"math"
)
// floatsEqual determines if two values are within epsilon of each other.
func floatsEqual(f1, f2, epsilon float64) bool {
return math.Abs(f1-f2) < epsilon
}
// floatsDeciEqual determines if two values are within 10^-1 of each other.
func floatsDeciEqual(f1, f2 float64) bool {
return math.Abs(f1-f2) < 0.1
}
// floatsCentiEqual determines if two values are within 10^-2 of each other.
func floatsCentiEqual(f1, f2 float64) bool {
return math.Abs(f1-f2) < 0.01
}
// floatsMilliEqual determines if two values are within 10^-3 of each other.
func floatsMilliEqual(f1, f2 float64) bool {
return math.Abs(f1-f2) < 0.001
}
// floatsNanoEqual determines if two values are within 10^-9 of each other.
func floatsNanoEqual(f1, f2 float64) bool {
return math.Abs(f1-f2) < 0.000000001
}
// floatsPicoEqual determines if two values are within 10^-12 of each other.
func floatsPicoEqual(f1, f2 float64) bool {
return math.Abs(f1-f2) < 0.000000000001
}