-
Notifications
You must be signed in to change notification settings - Fork 0
/
comp.go
46 lines (40 loc) · 902 Bytes
/
comp.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
45
46
package libwx
const (
ToleranceExact = float64(0.0)
Tolerance0 = float64(1.0)
Tolerance1 = float64(0.1)
Tolerance01 = float64(0.01)
Tolerance001 = float64(0.001)
Tolerace1 = Tolerance1 // deprecated; wasa a typo in a previous release
)
func Float64Compare(a, b, tolerance float64) int {
if a > b+tolerance {
return 1
}
if a < b-tolerance {
return -1
}
return 0
}
func IntCompare(a, b int) int {
if a > b {
return 1
}
if a < b {
return -1
}
return 0
}
func Float64Equal(a, b, tolerance float64) bool {
return 0 == Float64Compare(a, b, tolerance)
}
func CurriedFloat64Compare(tolerance float64) func(float64, float64) int {
return func(a, b float64) int {
return Float64Compare(a, b, tolerance)
}
}
func CurriedFloat64Equal(tolerance float64) func(float64, float64) bool {
return func(a, b float64) bool {
return Float64Equal(a, b, tolerance)
}
}