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