-
Notifications
You must be signed in to change notification settings - Fork 0
/
arithmetic.go
47 lines (38 loc) · 951 Bytes
/
arithmetic.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
// Package arithmetic provides basic arithmetic functions without the need for type casting when working with go.
package arithmetic
// DivideIntsReturnFloat divides 2 integers and returns a float64 as output
func DivideIntsReturnFloat(numerator int, denominator int) float64 {
return float64(numerator) / float64(denominator)
}
// MinInt returns the minimum of 2 integers
func MinInt(i, j int) int {
if i < j {
return i
}
return j
}
// MinInts returns the minimum of the input integers.
func MinInts(min int, others ...int) int {
for i := 0; i < len(others); i++ {
if others[i] < min {
min = others[i]
}
}
return min
}
// MaxInt returns the maximum of 2 integers
func MaxInt(i, j int) int {
if i > j {
return i
}
return j
}
// MaxInts returns the maximum of the input integers.
func MaxInts(max int, others ...int) int {
for i := 0; i < len(others); i++ {
if others[i] > max {
max = others[i]
}
}
return max
}