-
-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathtest_utils_test.go
More file actions
28 lines (26 loc) · 684 Bytes
/
Copy pathtest_utils_test.go
File metadata and controls
28 lines (26 loc) · 684 Bytes
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
package stats_test
// Approximate float comparisons
// Taken from the standard library's math/all_test.go
func tolerance(a, b, e float64) bool {
// Multiplying by e here can underflow denormal values to zero.
// Check a==b so that at least if a and b are small and identical
// we say they match.
if a == b {
return true
}
d := a - b
if d < 0 {
d = -d
}
// note: b is correct (expected) value, a is actual value.
// make error tolerance a fraction of b, not a.
if b != 0 {
e = e * b
if e < 0 {
e = -e
}
}
return d < e
}
func close(a, b float64) bool { return tolerance(a, b, 1e-14) }
func veryclose(a, b float64) bool { return tolerance(a, b, 4e-16) }