-
Notifications
You must be signed in to change notification settings - Fork 0
/
float32.go
50 lines (45 loc) · 1.02 KB
/
float32.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
package gomath
// MaxFloat32 takes in two or more integers and returns
// the maximum of them
func MaxFloat32(a float32, rem ...float32) float32 {
res := a
for _, v := range rem {
if v > res {
res = v
}
}
return res
}
// MinFloat32 takes in two or more integers and returns
// the maximum of them
func MinFloat32(a float32, rem ...float32) float32 {
res := a
for _, v := range rem {
if v < res {
res = v
}
}
return res
}
// AbsFloat32 takes an integer and returns its absolute
// value
func AbsFloat32(a float32) float32 {
return MaxFloat32(a, -a)
}
// ClampFloat32 will clamp a given value between a low and
// high value inclusively.
func ClampFloat32(low, high, val float32) (result float32) {
if val < low {
result = low
} else if val > high {
result = high
} else {
result = val
}
return
}
// ScaleFloat32 will scale a number from the old range
// to the new range
func ScaleFloat32(low, high, oldLow, oldHigh, value float32) float32 {
return low + (high-low)*((value-oldLow)/(oldHigh-oldLow))
}