-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.go
52 lines (45 loc) · 854 Bytes
/
math.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
52
package common
// ClampFloat32 limits the x value between min and max values.
func ClampFloat32(x, min, max float32) float32 {
if x < min {
return min
} else if x > max {
return max
} else {
return x
}
}
// ClampFloat64 limits the x value between min and max values.
func ClampFloat64(x, min, max float64) float64 {
if x < min {
return min
} else if x > max {
return max
} else {
return x
}
}
// ClampInt limits the x value between min and max values.
func ClampInt(x, min, max int) int {
if x < min {
return min
} else if x > max {
return max
} else {
return x
}
}
//MaxFloat32 returns the maximum of two floats.
func MaxFloat32(a, b float32) float32 {
if b > a {
return b
}
return a
}
//MinFloat32 returns the minimum of two floats.
func MinFloat32(a, b float32) float32 {
if b < a {
return b
}
return a
}