forked from NullHypothesis/mlgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
equal.go
43 lines (38 loc) · 815 Bytes
/
equal.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 mlgo
import "math"
func ApproximatelyEqual(a, b, epsilon float64) bool {
var t float64
if math.Abs(a) < math.Abs(b) {
t = math.Abs(b) * epsilon
} else {
t = math.Abs(a) * epsilon
}
return math.Abs(a-b) <= t
}
func EssentiallyEqual(a, b, epsilon float64) bool {
var t float64
if math.Abs(a) > math.Abs(b) {
t = math.Abs(b) * epsilon
} else {
t = math.Abs(a) * epsilon
}
return math.Abs(a-b) <= t
}
func DefinitelyGreaterThan(a, b, epsilon float64) bool {
var t float64
if math.Abs(a) < math.Abs(b) {
t = math.Abs(b) * epsilon
} else {
t = math.Abs(a) * epsilon
}
return (a - b) > t
}
func DefinitelyLessThan(a, b, epsilon float64) bool {
var t float64
if math.Abs(a) < math.Abs(b) {
t = math.Abs(b) * epsilon
} else {
t = math.Abs(a) * epsilon
}
return (a - b) < t
}