Class MathUtils

java.lang.Object
org.pkl.core.util.MathUtils

public final class MathUtils extends Object
  • Method Details

    • roundToLong

      public static long roundToLong(double x, RoundingMode mode)
    • isMathematicalInteger

      public static boolean isMathematicalInteger(double x)
    • isPowerOfTwo

      public static boolean isPowerOfTwo(long x)
      Returns true if x represents a power of two.

      This differs from Long.bitCount(x) == 1, because Long.bitCount(Long.MIN_VALUE) == 1, but Long.MIN_VALUE is not a power of two.

    • isPowerOfTwo

      public static boolean isPowerOfTwo(double x)
      Returns true if x is exactly equal to 2^k for some finite integer k.
    • checkedPow

      public static long checkedPow(long b, int k)
      Returns the b to the kth power, provided it does not overflow.
      Throws:
      ArithmeticException - if b to the kth power overflows in signed long arithmetic
    • gcd

      public static long gcd(long a, long b)
      Returns the greatest common divisor of a, b. Returns 0 if a == 0 && b == 0.
      Throws:
      IllegalArgumentException - if a < 0 or b < 0
    • checkedMultiply

      public static long checkedMultiply(long a, long b)
      Returns the product of a and b, provided it does not overflow.
      Throws:
      ArithmeticException - if a * b overflows in signed long arithmetic