Package de.tilman_neumann.jml.roots
Class SqrtReal
java.lang.Object
de.tilman_neumann.jml.roots.SqrtReal
public class SqrtReal
extends java.lang.Object
Compute square root of large numbers using Heron's method with a good initial guess.
Adapted from http://www.merriampark.com/bigsqrt.htm
-
Constructor Summary
Constructors Constructor Description SqrtReal()
-
Method Summary
Modifier and Type Method Description static void
main(java.lang.String[] argv)
Test.static java.math.BigDecimal
sqrt(java.math.BigDecimal x, Scale resultScale)
Compute square root.static java.math.BigDecimal
sqrt(java.math.BigDecimal x, java.math.BigDecimal guess, Scale resultScale)
Compute square root with initial guess.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
SqrtReal
public SqrtReal()
-
-
Method Details
-
sqrt
Compute square root.- Parameters:
x
- argumentresultScale
- desired precision in after-comma digits- Returns:
- sqrt(x) with error < 0.5*10^-resultScale, i.e. resultScale decimal digits are rounded correctly
-
sqrt
public static java.math.BigDecimal sqrt(java.math.BigDecimal x, java.math.BigDecimal guess, Scale resultScale)Compute square root with initial guess.- Parameters:
x
- argumentguess
- initial guess of sqrt(x)resultScale
- desired precision in after-comma digits- Returns:
- sqrt(x) with error < 0.5*10^-resultScale, i.e. resultScale decimal digits are rounded correctly
-
main
public static void main(java.lang.String[] argv)Test.- Parameters:
argv
- command line arguments
-