From 29de09a2372bc0b9189bd5283ac7cfac3742f80e Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Fri, 12 Feb 2021 09:43:10 +0100 Subject: [PATCH] Added NthRoot{,64} methods. --- ints/math.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ints/math.go b/ints/math.go index 86c8225..05c9065 100644 --- a/ints/math.go +++ b/ints/math.go @@ -72,6 +72,16 @@ func Norm64(i int64) int64 { return 0 } +// NthRoot returns the nth root of i. +func NthRoot(i, n int) int { + return int(math.Pow(float64(i), 1/float64(n))) +} + +// NthRoot64 returns the nth root of i. +func NthRoot64(i, n int64) int64 { + return int64(math.Pow(float64(i), 1/float64(n))) +} + // SubAbs subtracts a from b and returns the absolute value of the result. func SubAbs(a, b int) int { if a > b {