diff options
author | siddharth ravikumar <s@ricketyspace.net> | 2022-11-14 10:53:33 -0500 |
---|---|---|
committer | siddharth ravikumar <s@ricketyspace.net> | 2022-11-14 10:53:33 -0500 |
commit | b433086ab4e3d73b12f34b556323ee4c8fab293f (patch) | |
tree | 9d1df23a8bec33cf5fe7d0fb2f0f18c2e223c1ef /lib/cbrt.go | |
parent | 58fe25a643a9bbbcc0d4e68e5a59f69acc0cef69 (diff) |
lib: `BigCubeRoot`: refactor iteration
Diffstat (limited to 'lib/cbrt.go')
-rw-r--r-- | lib/cbrt.go | 7 |
1 files 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 |