22
22
import de .tilman_neumann .jml .precision .Magnitude ;
23
23
import de .tilman_neumann .jml .precision .Scale ;
24
24
import de .tilman_neumann .jml .powers .Pow2 ;
25
- import de .tilman_neumann .util .ConfigUtil ;
26
- import de .tilman_neumann .util .TimeUtil ;
27
25
28
26
import static de .tilman_neumann .jml .base .BigDecimalConstants .F_0 ;
29
27
import static de .tilman_neumann .jml .base .BigIntConstants .*;
36
34
*/
37
35
public class SqrtReal {
38
36
private static final Logger LOG = LogManager .getLogger (SqrtReal .class );
39
-
37
+ private static final boolean DEBUG = false ;
38
+
40
39
/**
41
40
* Compute square root.
42
41
*
@@ -47,7 +46,7 @@ public class SqrtReal {
47
46
public static BigDecimal sqrt (BigDecimal x , Scale resultScale ) {
48
47
// get initial guess correct to double precision (52 bit)
49
48
BigDecimal guess = getInitialApproximation (x );
50
- // LOG.debug("initial guess: sqrt(" + x + ") ~ " + guess);
49
+ if ( DEBUG ) LOG .debug ("initial guess: sqrt(" + x + ") ~ " + guess );
51
50
// iteration
52
51
return sqrt (x , guess , resultScale );
53
52
}
@@ -107,9 +106,9 @@ public static BigDecimal sqrt(BigDecimal x, BigDecimal guess, Scale resultScale)
107
106
lastGuess = guess ;
108
107
guess = BigDecimalMath .divide (x , guess , internalScale );
109
108
guess = Pow2 .divPow2 (guess .add (lastGuess ), 1 );
110
- // LOG.debug("next guess: sqrt(" + x + ") ~ " + guess);
109
+ if ( DEBUG ) LOG .debug ("next guess: sqrt(" + x + ") ~ " + guess );
111
110
error = guess .subtract (lastGuess ).abs ();
112
- // LOG.debug("error = " + error);
111
+ if ( DEBUG ) LOG .debug ("error = " + error );
113
112
} while (error .compareTo (maxAllowedError )>=0 );
114
113
115
114
return resultScale .applyTo (guess );
0 commit comments