summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-11-14 10:53:33 -0500
committersiddharth ravikumar <s@ricketyspace.net>2022-11-14 10:53:33 -0500
commitb433086ab4e3d73b12f34b556323ee4c8fab293f (patch)
tree9d1df23a8bec33cf5fe7d0fb2f0f18c2e223c1ef
parent58fe25a643a9bbbcc0d4e68e5a59f69acc0cef69 (diff)
lib: `BigCubeRoot`: refactor iteration
-rw-r--r--lib/cbrt.go7
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