Class MissingMath


  • public abstract class MissingMath
    extends java.lang.Object
    Math utilities missing from Math.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.math.BigDecimal[] EXP_COEF
      Coefficients for the Taylor series expansion of the exponential function.
      private static java.math.MathContext MC256
      Binary 256 octuple precision roughly corresponds to 71.34 decimal digits.
    • Constructor Summary

      Constructors 
      Constructor Description
      MissingMath()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double acosh​(double arg)  
      static double asinh​(double arg)  
      static double atan2​(double y, double x)
      https://math.stackexchange.com/questions/1098487/atan2-faster-approximation/1105038
      static double atanh​(double arg)  
      static java.math.BigDecimal cos​(java.math.BigDecimal arg)  
      static java.math.BigDecimal divide​(java.math.BigDecimal numerator, java.math.BigDecimal denominator)  
      private static java.math.BigDecimal doInternalCos​(java.math.BigDecimal arg)  
      static java.math.BigDecimal exp​(java.math.BigDecimal arg)  
      static double factorial​(int arg)
      13! does not fit in an int, and 21! does not fit in a long - that's why this method returns a double.
      (package private) static double factorialDouble​(int arg)  
      (package private) static int factorialInt​(int arg)  
      (package private) static long factorialLong​(int arg)  
      static int gcd​(int[] vals)  
      static int gcd​(int val1, int val2)
      Greatest Common Denominator
      static int gcd​(int val1, int... vals)  
      static long gcd​(long[] vals)  
      static long gcd​(long val1, long val2)
      Greatest Common Denominator
      static long gcd​(long val1, long... vals)  
      static double hypot​(double arg1, double arg2)  
      static java.math.BigDecimal hypot​(java.math.BigDecimal arg1, java.math.BigDecimal arg2)  
      static java.math.BigDecimal log​(java.math.BigDecimal arg)  
      static double log10​(double arg, double replacement)
      For very small arguments (regardless of sign) the replacement is returned instead
      static double logistic​(double arg)  
      static double logit​(double arg)  
      static int magnitude​(java.math.BigDecimal arg)
      Returns a rough approximation of Math.log10(double) for BigDecimal.
      static double max​(double... values)  
      static double max​(double a, double b)  
      static double max​(double a, double b, double c)  
      static double max​(double a, double b, double c, double d)  
      static int max​(int... values)  
      static int max​(int a, int b)  
      static int max​(int a, int b, int c)  
      static int max​(int a, int b, int c, int d)  
      static long max​(long... values)  
      static long max​(long a, long b)  
      static long max​(long a, long b, long c)  
      static long max​(long a, long b, long c, long d)  
      static double min​(double... values)  
      static double min​(double a, double b)  
      static double min​(double a, double b, double c)  
      static double min​(double a, double b, double c, double d)  
      static int min​(int... values)  
      static int min​(int a, int b)  
      static int min​(int a, int b, int c)  
      static int min​(int a, int b, int c, int d)  
      static long min​(long... values)  
      static long min​(long a, long b)  
      static long min​(long a, long b, long c)  
      static long min​(long a, long b, long c, long d)  
      static double norm​(double... values)  
      static double norm​(double a, double b)  
      static double norm​(double a, double b, double c)  
      static double norm​(double a, double b, double c, double d)  
      static java.math.BigDecimal pow​(java.math.BigDecimal arg1, java.math.BigDecimal arg2)  
      static double power​(double arg, int param)  
      static long power​(long arg, int param)  
      static java.math.BigDecimal power​(java.math.BigDecimal arg, int param)  
      static double root​(double arg, int param)  
      static java.math.BigDecimal root​(java.math.BigDecimal arg, int param)  
      static int roundToInt​(double value)  
      static double scale​(double arg, int param)  
      static java.math.BigDecimal signum​(java.math.BigDecimal arg)  
      static java.math.BigDecimal sin​(java.math.BigDecimal arg)  
      static double sqrt1px2​(double arg)  
      static java.math.BigDecimal tanh​(java.math.BigDecimal arg)  
      static int toMinIntExact​(long... values)  
      static int toMinIntExact​(long a, long b)  
      static int toMinIntExact​(long a, long b, long c)  
      static int toMinIntExact​(long a, long b, long c, long d)  
      • Methods inherited from class java.lang.Object

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

      • EXP_COEF

        private static final java.math.BigDecimal[] EXP_COEF
        Coefficients for the Taylor series expansion of the exponential function.
      • MC256

        private static final java.math.MathContext MC256
        Binary 256 octuple precision roughly corresponds to 71.34 decimal digits. Here we set it higher (for intermediate calculations) to enable end-results that are accurate to 71 decimal digits.

        https://en.wikipedia.org/wiki/IEEE_754

    • Constructor Detail

      • MissingMath

        public MissingMath()
    • Method Detail

      • acosh

        public static double acosh​(double arg)
      • asinh

        public static double asinh​(double arg)
      • atan2

        public static double atan2​(double y,
                                   double x)

        https://math.stackexchange.com/questions/1098487/atan2-faster-approximation/1105038

        This is about 10x faster than Math.atan2(double, double)

      • atanh

        public static double atanh​(double arg)
      • cos

        public static java.math.BigDecimal cos​(java.math.BigDecimal arg)
      • divide

        public static java.math.BigDecimal divide​(java.math.BigDecimal numerator,
                                                  java.math.BigDecimal denominator)
      • exp

        public static java.math.BigDecimal exp​(java.math.BigDecimal arg)
      • factorial

        public static double factorial​(int arg)
        13! does not fit in an int, and 21! does not fit in a long - that's why this method returns a double.
      • gcd

        public static int gcd​(int val1,
                              int val2)
        Greatest Common Denominator
      • gcd

        public static int gcd​(int val1,
                              int... vals)
      • gcd

        public static int gcd​(int[] vals)
      • gcd

        public static long gcd​(long val1,
                               long... vals)
      • gcd

        public static long gcd​(long val1,
                               long val2)
        Greatest Common Denominator
      • gcd

        public static long gcd​(long[] vals)
      • hypot

        public static java.math.BigDecimal hypot​(java.math.BigDecimal arg1,
                                                 java.math.BigDecimal arg2)
      • hypot

        public static double hypot​(double arg1,
                                   double arg2)
      • log

        public static java.math.BigDecimal log​(java.math.BigDecimal arg)
      • log10

        public static double log10​(double arg,
                                   double replacement)
        For very small arguments (regardless of sign) the replacement is returned instead
      • logistic

        public static double logistic​(double arg)
      • logit

        public static double logit​(double arg)
      • magnitude

        public static int magnitude​(java.math.BigDecimal arg)
        Returns a rough approximation of Math.log10(double) for BigDecimal.
        • For numbers like 10^n it returns the exact correct number, n.
        • The magnitude of 0.0 is 0.
        • The error is [0.0,1.0) and the returned value is never more than the actual/correct value. For 999.0 the correct value is close to 3, but this method returns 2, as the implementation simply counts the digits.
        • Works for negative numbers as the sign is disregarded.
        • Works for fractional numbers 0.1, 0.0456, 1.2 or whatever.
      • max

        public static double max​(double... values)
      • max

        public static double max​(double a,
                                 double b)
      • max

        public static double max​(double a,
                                 double b,
                                 double c)
      • max

        public static double max​(double a,
                                 double b,
                                 double c,
                                 double d)
      • max

        public static int max​(int... values)
      • max

        public static int max​(int a,
                              int b)
      • max

        public static int max​(int a,
                              int b,
                              int c)
      • max

        public static int max​(int a,
                              int b,
                              int c,
                              int d)
      • max

        public static long max​(long... values)
      • max

        public static long max​(long a,
                               long b)
      • max

        public static long max​(long a,
                               long b,
                               long c)
      • max

        public static long max​(long a,
                               long b,
                               long c,
                               long d)
      • min

        public static double min​(double... values)
      • min

        public static double min​(double a,
                                 double b)
      • min

        public static double min​(double a,
                                 double b,
                                 double c)
      • min

        public static double min​(double a,
                                 double b,
                                 double c,
                                 double d)
      • min

        public static int min​(int... values)
      • min

        public static int min​(int a,
                              int b)
      • min

        public static int min​(int a,
                              int b,
                              int c)
      • min

        public static int min​(int a,
                              int b,
                              int c,
                              int d)
      • min

        public static long min​(long... values)
      • min

        public static long min​(long a,
                               long b)
      • min

        public static long min​(long a,
                               long b,
                               long c)
      • min

        public static long min​(long a,
                               long b,
                               long c,
                               long d)
      • norm

        public static double norm​(double... values)
      • norm

        public static double norm​(double a,
                                  double b)
      • norm

        public static double norm​(double a,
                                  double b,
                                  double c)
      • norm

        public static double norm​(double a,
                                  double b,
                                  double c,
                                  double d)
      • pow

        public static java.math.BigDecimal pow​(java.math.BigDecimal arg1,
                                               java.math.BigDecimal arg2)
      • power

        public static java.math.BigDecimal power​(java.math.BigDecimal arg,
                                                 int param)
      • power

        public static double power​(double arg,
                                   int param)
      • power

        public static long power​(long arg,
                                 int param)
      • root

        public static java.math.BigDecimal root​(java.math.BigDecimal arg,
                                                int param)
      • root

        public static double root​(double arg,
                                  int param)
      • roundToInt

        public static int roundToInt​(double value)
      • scale

        public static double scale​(double arg,
                                   int param)
      • signum

        public static java.math.BigDecimal signum​(java.math.BigDecimal arg)
      • sin

        public static java.math.BigDecimal sin​(java.math.BigDecimal arg)
      • sqrt1px2

        public static double sqrt1px2​(double arg)
      • tanh

        public static java.math.BigDecimal tanh​(java.math.BigDecimal arg)
      • toMinIntExact

        public static int toMinIntExact​(long... values)
      • toMinIntExact

        public static int toMinIntExact​(long a,
                                        long b)
      • toMinIntExact

        public static int toMinIntExact​(long a,
                                        long b,
                                        long c)
      • toMinIntExact

        public static int toMinIntExact​(long a,
                                        long b,
                                        long c,
                                        long d)
      • doInternalCos

        private static java.math.BigDecimal doInternalCos​(java.math.BigDecimal arg)
      • factorialDouble

        static double factorialDouble​(int arg)
      • factorialInt

        static int factorialInt​(int arg)
      • factorialLong

        static long factorialLong​(int arg)