Package org.jctools.util
Class Pow2
- java.lang.Object
-
- org.jctools.util.Pow2
-
public final class Pow2 extends Object
Power of 2 utility functions.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_POW2
-
Constructor Summary
Constructors Constructor Description Pow2()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
align(long value, int alignment)
Align a value to the next multiple up of alignment.static boolean
isPowerOfTwo(int value)
static int
roundToPowerOfTwo(int value)
-
-
-
Field Detail
-
MAX_POW2
public static final int MAX_POW2
- See Also:
- Constant Field Values
-
-
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.
-
-