Class ExtendedPrecision

java.lang.Object
org.apache.commons.statistics.distribution.ExtendedPrecision

final class ExtendedPrecision extends Object
Computes extended precision floating-point operations.

Extended precision computation is delegated to the DD class. The methods here verify the arguments to the computations will not overflow.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final double
    Threshold for a big number that may overflow when squared.
    private static final int
    Approximate x squared value where exp(-0.5*x*x) == 0.
    private static final int
    X squared value where exp(-0.5*x*x) cannot increase accuracy using the round-off from x squared.
    private static final double
    Scale down by 2^600.
    private static final double
    Scale up by 2^600.
    private static final double
    Threshold for a small number that may underflow when squared.
    (package private) static final org.apache.commons.numbers.core.DD
    sqrt(2 pi) as a double-double number.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    No instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static double
    computeSqrt2aa(double a)
    Compute sqrt(2 * a * a).
    private static double
    computeXsqrt2pi(double a)
    Compute a * sqrt(2 * pi).
    (package private) static double
    expmhxx(double x)
    Compute exp(-0.5*x*x) with high accuracy.
    private static double
    expxx(double a, double b)
    Compute exp(a+b) with high accuracy assuming a+b = a.
    (package private) static double
    sqrt2xx(double x)
    Compute sqrt(2 * x * x).
    (package private) static double
    xsqrt2pi(double x)
    Multiply the term by sqrt(2 pi).

    Methods inherited from class java.lang.Object

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

    • SQRT2PI

      static final org.apache.commons.numbers.core.DD SQRT2PI
      sqrt(2 pi) as a double-double number. Divided into two parts from the value sqrt(2 pi) computed to 64 decimal digits.
    • BIG

      private static final double BIG
      Threshold for a big number that may overflow when squared. 2^500.
      See Also:
    • SMALL

      private static final double SMALL
      Threshold for a small number that may underflow when squared. 2^-500.
      See Also:
    • SCALE_UP

      private static final double SCALE_UP
      Scale up by 2^600.
      See Also:
    • SCALE_DOWN

      private static final double SCALE_DOWN
      Scale down by 2^600.
      See Also:
    • EXP_M_HALF_XX_MIN_VALUE

      private static final int EXP_M_HALF_XX_MIN_VALUE
      X squared value where exp(-0.5*x*x) cannot increase accuracy using the round-off from x squared.
      See Also:
    • EXP_M_HALF_XX_MAX_VALUE

      private static final int EXP_M_HALF_XX_MAX_VALUE
      Approximate x squared value where exp(-0.5*x*x) == 0. This is above -2 * ln(2^-1074) due to rounding performed within the exp function.
      See Also:
  • Constructor Details

    • ExtendedPrecision

      private ExtendedPrecision()
      No instances.
  • Method Details

    • xsqrt2pi

      static double xsqrt2pi(double x)
      Multiply the term by sqrt(2 pi).
      Parameters:
      x - Value (assumed to be positive)
      Returns:
      x * sqrt(2 pi)
    • computeXsqrt2pi

      private static double computeXsqrt2pi(double a)
      Compute a * sqrt(2 * pi).
      Parameters:
      a - Value
      Returns:
      the result
    • sqrt2xx

      static double sqrt2xx(double x)
      Compute sqrt(2 * x * x).

      The result is computed using a high precision computation of sqrt(2 * x * x) avoiding underflow or overflow of x squared.

      Parameters:
      x - Value (assumed to be positive)
      Returns:
      sqrt(2 * x * x)
    • computeSqrt2aa

      private static double computeSqrt2aa(double a)
      Compute sqrt(2 * a * a).
      Parameters:
      a - Value
      Returns:
      the result
    • expmhxx

      static double expmhxx(double x)
      Compute exp(-0.5*x*x) with high accuracy. This is performed using information in the round-off from x*x.

      This is accurate at large x to 1 ulp until exp(-0.5*x*x) is close to sub-normal. For very small exp(-0.5*x*x) the adjustment is sub-normal and bits can be lost in the adjustment for a max observed error of < 2 ulp.

      At small x the accuracy cannot be improved over using exp(-0.5*x*x). This occurs at x <= sqrt(2).

      Parameters:
      x - Value
      Returns:
      exp(-0.5*x*x)
      See Also:
    • expxx

      private static double expxx(double a, double b)
      Compute exp(a+b) with high accuracy assuming a+b = a.

      This is accurate at large positive a to 1 ulp. If a is negative and exp(a) is close to sub-normal a bit of precision may be lost when adjusting result as the adjustment is sub-normal (max observed error < 2 ulp). For the use case of multiplication of a number less than 1 by exp(-x*x), a = -x*x, the result will be sub-normal and the rounding error is lost.

      At small |a| the accuracy cannot be improved over using exp(a) as the round-off is too small to create terms that can adjust the standard result by more than 0.5 ulp. This occurs at |a| <= 1.

      Parameters:
      a - High bits of a split number
      b - Low bits of a split number
      Returns:
      exp(a+b)
      See Also: