Class MathUtils


  • final class MathUtils
    extends java.lang.Object
    This class exposes package private utilities for other classes. Thus, all methods are assumed to be invoked with correct arguments, so these are not checked at all.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static long A_10  
      private static long C_10  
      private static long C_2  
      private static long[] g  
      (package private) static int H  
      (package private) static int K_MAX  
      (package private) static int K_MIN  
      private static long[] pow10  
      private static int Q_10  
      private static int Q_2  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MathUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static int flog10pow2​(int e)
      Returns the unique integer k such that 10k ≤ 2e < 10k+1.
      (package private) static int flog10threeQuartersPow2​(int e)
      Returns the unique integer k such that 10k ≤ 3/4 · 2e < 10k+1.
      (package private) static int flog2pow10​(int e)
      Returns the unique integer k such that 2k ≤ 10e < 2k+1.
      (package private) static long g0​(int k)
      Returns g0 as described in g1(int).
      (package private) static long g1​(int k)
      Let 10-k = β 2r, for the unique pair of integer r and real β meeting 2125 ≤ β < 2126.
      (package private) static long multiplyHigh​(long x, long y)  
      (package private) static long pow10​(int e)
      Returns 10e.
      • Methods inherited from class java.lang.Object

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

      • MathUtils

        private MathUtils()
    • Method Detail

      • pow10

        static long pow10​(int e)
        Returns 10e.
        Parameters:
        e - The exponent which must meet 0 ≤ e ≤ H.
        Returns:
        10e.
      • flog10pow2

        static int flog10pow2​(int e)
        Returns the unique integer k such that 10k ≤ 2e < 10k+1.

        The result is correct when |e| ≤ 5_456_721. Otherwise the result is undefined.

        Parameters:
        e - The exponent of 2, which should meet |e| ≤ 5_456_721 for safe results.
        Returns:
        ⌊log102e⌋.
      • flog10threeQuartersPow2

        static int flog10threeQuartersPow2​(int e)
        Returns the unique integer k such that 10k ≤ 3/4 · 2e < 10k+1.

        The result is correct when -2_956_395 ≤ e ≤ 2_500_325. Otherwise the result is undefined.

        Parameters:
        e - The exponent of 2, which should meet -2_956_395 ≤ e ≤ 2_500_325 for safe results.
        Returns:
        ⌊log10(3/4 · 2e)⌋.
      • flog2pow10

        static int flog2pow10​(int e)
        Returns the unique integer k such that 2k ≤ 10e < 2k+1.

        The result is correct when |e| ≤ 1_838_394. Otherwise the result is undefined.

        Parameters:
        e - The exponent of 10, which should meet |e| ≤ 1_838_394 for safe results.
        Returns:
        ⌊log210e⌋.
      • g1

        static long g1​(int k)
        Let 10-k = β 2r, for the unique pair of integer r and real β meeting 2125 ≤ β < 2126. Further, let g = ⌊β⌋ + 1. Split g into the higher 63 bits g1 and the lower 63 bits g0. Thus, g1 = ⌊g 2-63⌋ and g0 = g - g1 263.

        This method returns g1 while g0(int) returns g0.

        If needed, the exponent r can be computed as r = flog2pow10(-k) - 125 (see flog2pow10(int)).

        Parameters:
        k - The exponent of 10, which must meet K_MIN ≤ e ≤ K_MAX.
        Returns:
        g1 as described above.
      • g0

        static long g0​(int k)
        Returns g0 as described in g1(int).
        Parameters:
        k - The exponent of 10, which must meet K_MIN ≤ e ≤ K_MAX.
        Returns:
        g0 as described in g1(int).
      • multiplyHigh

        static long multiplyHigh​(long x,
                                 long y)