Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TilmanNeumann committed Jan 1, 2025
1 parent 5c5a053 commit 3780e12
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/main/java/de/tilman_neumann/jml/roots/SqrtReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import de.tilman_neumann.jml.precision.Magnitude;
import de.tilman_neumann.jml.precision.Scale;
import de.tilman_neumann.jml.powers.Pow2;
import de.tilman_neumann.util.ConfigUtil;
import de.tilman_neumann.util.TimeUtil;

import static de.tilman_neumann.jml.base.BigDecimalConstants.F_0;
import static de.tilman_neumann.jml.base.BigIntConstants.*;
Expand All @@ -36,7 +34,8 @@
*/
public class SqrtReal {
private static final Logger LOG = LogManager.getLogger(SqrtReal.class);

private static final boolean DEBUG = false;

/**
* Compute square root.
*
Expand All @@ -47,7 +46,7 @@ public class SqrtReal {
public static BigDecimal sqrt(BigDecimal x, Scale resultScale) {
// get initial guess correct to double precision (52 bit)
BigDecimal guess = getInitialApproximation(x);
//LOG.debug("initial guess: sqrt(" + x + ") ~ " + guess);
if (DEBUG) LOG.debug("initial guess: sqrt(" + x + ") ~ " + guess);
// iteration
return sqrt(x, guess, resultScale);
}
Expand Down Expand Up @@ -107,9 +106,9 @@ public static BigDecimal sqrt(BigDecimal x, BigDecimal guess, Scale resultScale)
lastGuess = guess;
guess = BigDecimalMath.divide(x, guess, internalScale);
guess = Pow2.divPow2(guess.add(lastGuess), 1);
//LOG.debug("next guess: sqrt(" + x + ") ~ " + guess);
if (DEBUG) LOG.debug("next guess: sqrt(" + x + ") ~ " + guess);
error = guess.subtract(lastGuess).abs();
//LOG.debug("error = " + error);
if (DEBUG) LOG.debug("error = " + error);
} while (error.compareTo(maxAllowedError)>=0);

return resultScale.applyTo(guess);
Expand Down

0 comments on commit 3780e12

Please sign in to comment.