Class SquareRoot

java.lang.Object
ffx.numerics.math.SquareRoot

public class SquareRoot extends Object
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 Type
    Method
    Description
    static double
    isqrt(double x2)
    Compute the inverse square root 1.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(String[] args)
    main.
    static double
    sqrt(double x2)
    Compute the square root of the input value x.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isqrt

      public static double isqrt(double x2)
      Compute the inverse square root 1.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

      public static void main(String[] args)
      main.
      Parameters:
      args - an array of String objects.
    • sqrt

      public static double sqrt(double x2)
      Compute the square root of the input value x. The method calls isqrt and then multiples by the input sqrt(x2) = x2 * isqrt(x2).
      Parameters:
      x2 - input value to take the square root of.
      Returns:
      the square root of x2.