Package ffx.numerics.math
Class SquareRoot
java.lang.Object
ffx.numerics.math.SquareRoot
Software based computation of square root and inverse square root.
The decimal accuracy compared to Math.sqrt is:
within 1.0e-13 for input values from 1.0e-2 to 1.0e3.
within 1.0e-12 for input values from
1.0e-4 to 1.0e4.
within 1.0e-11 for input values from 1.0e-5 to 1.0e5.
within 1.0e-10
for input values from 1.0e-8 to 1.0e8.
The "main" method performance test shows that the software implementation is slower than simply calling Math.sqrt.
- Since:
- 1.0
- Author:
- Michael J. Schnieders, Ported to Java from the GROMACS code in cinvsqrtdata.c
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
isqrt
(double x2) Compute the inverse square root1.0/sqrt(x2)
of the input value x2 using a look-up table and two iterations of Newton's method for finding roots of an equation.static void
main.static double
sqrt
(double x2) Compute the square root of the input value x.
-
Method Details
-
isqrt
public static double isqrt(double x2) Compute the inverse square root1.0/sqrt(x2)
of the input value x2 using a look-up table and two iterations of Newton's method for finding roots of an equation.- Parameters:
x2
- Input value.- Returns:
- the inverse square root ( 1 / sqrt(x2) ).
-
main
main.- Parameters:
args
- an array ofString
objects.
-
sqrt
public static double sqrt(double x2) Compute the square root of the input value x. The method callsisqrt
and then multiples by the inputsqrt(x2) = x2 * isqrt(x2)
.- Parameters:
x2
- input value to take the square root of.- Returns:
- the square root of x2.
-