From 92153118028b0bdc980c00dd4f79b3ebca5f4880 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sun, 7 Jun 2020 08:44:34 +0200 Subject: [PATCH] Added two missing int64 methods (Abs64 and SubAbs64). --- ints/math.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 {