Class MathUtil


  • public final class MathUtil
    extends Object
    Math static utility methods.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double acosh​(double a)
      Calculates inverse hyperbolic cosine of a double value.
      static double asinh​(double a)
      Calculates inverse hyperbolic sine of a double value.
      static double atanh​(double a)
      Calculates inverse hyperbolic tangent of a double value.
      static long gcd​(long a, long b)
      Return the greatest common divisor of a and b, consistently with BigInteger.gcd(BigInteger).
      static double log​(double base, double x)
      Calculates logarithm in a given base with doubles.
      static int log​(long x, int base)
      Returns x <= 0 ? 0 : Math.floor(Math.log(x) / Math.log(base))
      static double sumRelativeErrorBound​(int numValues)
      Return a relative error bound for a sum of numValues positive doubles, computed using recursive summation, ie.
    • Method Detail

      • log

        public static int log​(long x,
                              int base)
        Returns x <= 0 ? 0 : Math.floor(Math.log(x) / Math.log(base))
        Parameters:
        base - must be > 1
      • log

        public static double log​(double base,
                                 double x)
        Calculates logarithm in a given base with doubles.
      • asinh

        public static double asinh​(double a)
        Calculates inverse hyperbolic sine of a double value.

        Special cases:

        • If the argument is NaN, then the result is NaN.
        • If the argument is zero, then the result is a zero with the same sign as the argument.
        • If the argument is infinite, then the result is infinity with the same sign as the argument.
      • acosh

        public static double acosh​(double a)
        Calculates inverse hyperbolic cosine of a double value.

        Special cases:

        • If the argument is NaN, then the result is NaN.
        • If the argument is +1, then the result is a zero.
        • If the argument is positive infinity, then the result is positive infinity.
        • If the argument is less than 1, then the result is NaN.
      • atanh

        public static double atanh​(double a)
        Calculates inverse hyperbolic tangent of a double value.

        Special cases:

        • If the argument is NaN, then the result is NaN.
        • If the argument is zero, then the result is a zero with the same sign as the argument.
        • If the argument is +1, then the result is positive infinity.
        • If the argument is -1, then the result is negative infinity.
        • If the argument's absolute value is greater than 1, then the result is NaN.
      • sumRelativeErrorBound

        public static double sumRelativeErrorBound​(int numValues)
        Return a relative error bound for a sum of numValues positive doubles, computed using recursive summation, ie. sum = x1 + ... + xn. NOTE: This only works if all values are POSITIVE so that Σ |xi| == |Σ xi|. This uses formula 3.5 from Higham, Nicholas J. (1993), "The accuracy of floating point summation", SIAM Journal on Scientific Computing.