@Test(expected = IllegalArgumentException.class) public void testNegativeRoundException() { Pow2.roundToPowerOfTwo(-1); fail(); }
public static int roundToPowerOfTwo(final int value) { if (value > MAX_POW2) { throw new IllegalArgumentException("There is no larger power of 2 int for value:"+value+" since it exceeds 2^31."); } if (value < 0) { throw new IllegalArgumentException("Given value:"+value+". Expecting value >= 0."); } final int nextPow2 = 1 << (32 - Integer.numberOfLeadingZeros(value - 1)); return nextPow2; }
Pow2 { public static int roundToPowerOfTwo(final int value) { if (value > MAX_POW2) { throw new IllegalArgumentException("There is no larger power of 2 int for value:"+value+" since it exceeds 2^31."); } if (value < 0) { throw new IllegalArgumentException("Given value:"+value+". Expecting value >= 0."); } final int nextPow2 = 1 << (32 - Integer.numberOfLeadingZeros(value - 1)); return nextPow2; } }
Pow2 { public static int roundToPowerOfTwo(final int value) { if (value > MAX_POW2) { throw new IllegalArgumentException("There is no larger power of 2 int for value:"+value+" since it exceeds 2^31."); } if (value < 0) { throw new IllegalArgumentException("Given value:"+value+". Expecting value >= 0."); } final int nextPow2 = 1 << (32 - Integer.numberOfLeadingZeros(value - 1)); return nextPow2; }  }
Pow2 { public static int roundToPowerOfTwo(final int value) { if (value > MAX_POW2) { throw new IllegalArgumentException("There is no larger power of 2 int for value:"+value+" since it exceeds 2^31."); } if (value < 0) { throw new IllegalArgumentException("Given value:"+value+". Expecting value >= 0."); } final int nextPow2 = 1 << (32 - Integer.numberOfLeadingZeros(value - 1)); return nextPow2; }  static int roundToPowerOfTwo(final int value); static boolean isPowerOfTwo(final int value); static long align(final long value, final int alignment); }
Pow2 { public static int roundToPowerOfTwo(final int value) { if (value > MAX_POW2) { throw new IllegalArgumentException("There is no larger power of 2 int for value:"+value+" since it exceeds 2^31."); } if (value < 0) { throw new IllegalArgumentException("Given value:"+value+". Expecting value >= 0."); } final int nextPow2 = 1 << (32 - Integer.numberOfLeadingZeros(value - 1)); return nextPow2; }  static int roundToPowerOfTwo(final int value); static boolean isPowerOfTwo(final int value); static long align(final long value, final int alignment); static final int MAX_POW2; }