From b433086ab4e3d73b12f34b556323ee4c8fab293f Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Mon, 14 Nov 2022 10:53:33 -0500 Subject: lib: `BigCubeRoot`: refactor iteration --- lib/cbrt.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/cbrt.go b/lib/cbrt.go index 451bb9b..df82c6e 100644 --- a/lib/cbrt.go +++ b/lib/cbrt.go @@ -41,10 +41,8 @@ func BigCubeRoot(a *big.Float) *big.Float { return z } - x0 := a // Initial guess. - max := 1000 // Max iterations. - i := 0 // Current iteration. - for i < max { + x0 := a // Initial guess. + for i := 0; i < 1000; i++ { // f(x0) / f'(x0) d := fx(x0) d = d.Quo(d, fxPrime(x0)) @@ -61,7 +59,6 @@ func BigCubeRoot(a *big.Float) *big.Float { return x1 } - i += 1 x0 = x1 } return nil -- cgit v1.2.3