Package de.tilman_neumann.jml.roots
Class SqrtReal
- java.lang.Object
-
- de.tilman_neumann.jml.roots.SqrtReal
-
public class SqrtReal extends Object
Compute square root of large numbers using Heron's method with a good initial guess. Adapted from http://www.merriampark.com/bigsqrt.htm- Author:
- Tilman Neumann
-
-
Constructor Summary
Constructors Constructor Description SqrtReal()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
main(String[] argv)
Test.static BigDecimal
sqrt(BigDecimal x, Scale resultScale)
Compute square root.static BigDecimal
sqrt(BigDecimal x, BigDecimal guess, Scale resultScale)
Compute square root with initial guess.
-
-
-
Method Detail
-
sqrt
public static BigDecimal sqrt(BigDecimal x, Scale resultScale)
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 BigDecimal sqrt(BigDecimal x, 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(String[] argv)
Test.- Parameters:
argv
- command line arguments
-
-