Class PowerOf2

    • Field Detail

      • MAX_INT

        public static final int MAX_INT
      • MAX_LONG

        public static final long MAX_LONG
      • INT_POWERS

        private static final int[] INT_POWERS
      • LN2

        private static double LN2
      • LONG_POWERS

        private static final long[] LONG_POWERS
      • exponent

        public final int exponent
    • Constructor Detail

      • PowerOf2

        PowerOf2​(int exp)
    • Method Detail

      • exponent

        public static int exponent​(double value)
      • find

        public static int find​(int value)
        If the input value is a power of 2 then the exponent is returned, if not a negative number is returned.
      • find

        public static int find​(long value)
        See Also:
        find(int)
      • isPowerOf2

        public static boolean isPowerOf2​(int value)
      • isPowerOf2

        public static boolean isPowerOf2​(long value)
      • largestNotGreaterThan

        public static int largestNotGreaterThan​(int value)
        Returns:
        The largest power of 2 that is less than or equal to the input (not greater than)
      • largestNotGreaterThan

        public static long largestNotGreaterThan​(long value)
        Returns:
        The largest power of 2 that is less than or equal to the input (not greater than)
      • powerOf2Larger

        public static int powerOf2Larger​(int value)
        Returns:
        The smallest integer exponent so that 2^exp >= value.
      • powerOf2Larger

        public static int powerOf2Larger​(long value)
        Returns:
        The smallest integer exponent so that 2^exp >= value.
      • powerOf2Smaller

        public static int powerOf2Smaller​(int value)
        Returns:
        The largest integer exponent so that 2^exp <= value.
      • powerOf2Smaller

        public static int powerOf2Smaller​(long value)
        Returns:
        The largest integer exponent so that 2^exp <= value.
      • powerOfInt2

        public static int powerOfInt2​(int exponent)
      • powerOfLong2

        public static long powerOfLong2​(int exponent)
      • smallestNotLessThan

        public static int smallestNotLessThan​(int value)
        Returns:
        The smallest power of 2 that is greater than or equal to the input (not less than)
      • smallestNotLessThan

        public static long smallestNotLessThan​(long value)
        Returns:
        The smallest power of 2 that is greater than or equal to the input (not less than)