Class Pow2


  • public final class Pow2
    extends Object
    Power of 2 utility functions.
    • Constructor Detail

      • Pow2

        public Pow2()
    • Method Detail

      • roundToPowerOfTwo

        public static int roundToPowerOfTwo​(int value)
        Parameters:
        value - from which next positive power of two will be found.
        Returns:
        the next positive power of 2, this value if it is a power of 2. Negative values are mapped to 1.
        Throws:
        IllegalArgumentException - is value is more than MAX_POW2 or less than 0
      • isPowerOfTwo

        public static boolean isPowerOfTwo​(int value)
        Parameters:
        value - to be tested to see if it is a power of two.
        Returns:
        true if the value is a power of 2 otherwise false.
      • align

        public static long align​(long value,
                                 int alignment)
        Align a value to the next multiple up of alignment. If the value equals an alignment multiple then it is returned unchanged.
        Parameters:
        value - to be aligned up.
        alignment - to be used, must be a power of 2.
        Returns:
        the value aligned to the next boundary.