Class IntegerUtil

java.lang.Object
ca.spottedleaf.common.util.IntegerUtil

public final class IntegerUtil extends Object
  • Field Details

  • Method Details

    • ceilLog2

      public static int ceilLog2(int value)
    • ceilLog2

      public static long ceilLog2(long value)
    • floorLog2

      public static int floorLog2(int value)
    • floorLog2

      public static int floorLog2(long value)
    • roundCeilLog2

      public static int roundCeilLog2(int value)
    • roundCeilLog2

      public static long roundCeilLog2(long value)
    • roundFloorLog2

      public static int roundFloorLog2(int value)
    • roundFloorLog2

      public static long roundFloorLog2(long value)
    • isPowerOfTwo

      public static boolean isPowerOfTwo(int n)
    • isPowerOfTwo

      public static boolean isPowerOfTwo(long n)
    • getTrailingBit

      public static int getTrailingBit(int n)
    • getTrailingBit

      public static long getTrailingBit(long n)
    • trailingZeros

      public static int trailingZeros(int n)
    • trailingZeros

      public static int trailingZeros(long n)
    • getDivisorMultiple

      public static int getDivisorMultiple(long numbers)
    • getDivisorShift

      public static int getDivisorShift(long numbers)
    • getDivisorNumbers

      public static long getDivisorNumbers(int d)
    • branchlessAbs

      public static int branchlessAbs(int val)
    • branchlessAbs

      public static long branchlessAbs(long val)
    • getUnsignedDivisorMagic

      public static long getUnsignedDivisorMagic(long divisor, int bits)
      Usage:
      
          static final long mult = getSimpleMultiplier(divisor, bits);
          long x = ...;
          long magic = x * mult;
          long divQ = magic >>> bits;
          long divR = ((magic & ((1L << bits) - 1L)) * divisor) >>> bits;
      
      
      Parameters:
      bits - The number of bits of precision for the returned result.
    • getLongMask

      public static long getLongMask(int bits)
    • getIntMask

      public static int getIntMask(int bits)
    • longValueExact

      public static long longValueExact(Number x)
      Returns the long value of the number, without discarding any fractional portion of the number.
      Parameters:
      x - The number
      Returns:
      The integer portion of the number
      Throws:
      ArithmeticException - If the number cannot be represented as a long