diff --git a/ints/math.go b/ints/math.go index 30c462e..86c8225 100644 --- a/ints/math.go +++ b/ints/math.go @@ -10,6 +10,14 @@ func Abs(i int) int { return i } +// Abs64 returns the absolute value of i. +func Abs64(i int64) int64 { + if 0 > i { + return -i + } + return i +} + // Min returns the minimum of a and b. func Min(a, b int) int { if a < b { @@ -72,6 +80,14 @@ func SubAbs(a, b int) int { return b - a } +// SubAbs64 subtracts a from b and returns the absolute value of the result. +func SubAbs64(a, b int64) int64 { + if a > b { + return a - b + } + return b - a +} + // Pow returns the power of base b to the exponent e. func Pow(b, e int) int { if 0 == e {