-
Notifications
You must be signed in to change notification settings - Fork 14
/
float.go
51 lines (39 loc) · 954 Bytes
/
float.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
47
48
49
50
51
package stl
// This file contains generic numerical functions for floating point processing
import (
"math"
)
// Pi is just math.Pi
const Pi = math.Pi
// TwoPi is math.Pi * 2
const TwoPi = math.Pi * 2
// HalfPi is math.Pi * 0.5
const HalfPi = math.Pi * 0.5
// QuarterPi is math.Pi * 0.25
const QuarterPi = math.Pi * 0.25
// AlmostEqual returns true, if a and b are equal allowing for numerical error tol.
func almostEqual32(a, b, tol float32) bool {
return math.Abs(float64(a-b)) <= float64(tol)
}
// Returns true, if a and b are equal allowing for numerical error tol.
func almostEqual64(a, b, tol float64) bool {
return math.Abs(a-b) <= tol
}
func min(a, b float32) float32 {
if a < b {
return a
}
return b
}
func min4(a, b, c, d float32) float32 {
return min(min(a, b), min(c, d))
}
func max(a, b float32) float32 {
if a > b {
return a
}
return b
}
func max4(a, b, c, d float32) float32 {
return max(max(a, b), max(c, d))
}