提交 7a29d484 authored 作者: LaughingMan's avatar LaughingMan

Remove nextPowerOf2(long) since it is now unused.

上级 952c39e1
......@@ -236,31 +236,6 @@ public class MathUtils {
return ++x;
}
/**
* Get the value that is equal to or higher than this value, and that is a
* power of two.
*
* @param x the original value
* @return the next power of two value
* @throws IllegalArgumentException if x < 0 or x > 0x4000000000000000
*/
public static long nextPowerOf2(long x) throws IllegalArgumentException {
if (x == 0) {
return 1;
} else if (x < 0 || x > 0x4000000000000000L ) {
throw new IllegalArgumentException("Argument out of range"
+ " [0x0-0x4000000000000000]. Argument was: " + x);
}
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x |= x >> 32;
return ++x;
}
/**
* Convert a long value to an int value. Values larger than the biggest int
* value is converted to the biggest int value, and values smaller than the
......
......@@ -26,7 +26,6 @@ public class TestMathUtils extends TestBase {
public void test() {
testRandom();
testNextPowerOf2Int();
testNextPowerOf2Long();
}
private void testRandom() {
......@@ -63,17 +62,4 @@ public class TestMathUtils extends TestBase {
}
}
private void testNextPowerOf2Long() {
// the largest power of two that fits into a long
final long LARGEST_POW2 = 0x4000000000000000L;
long[] testValues = { 0, 1, 2, 3, 4, 12, 17, 500, 1023,
LARGEST_POW2-500, LARGEST_POW2 };
long[] resultValues = { 1, 1, 2, 4, 4, 16, 32, 512, 1024,
LARGEST_POW2, LARGEST_POW2 };
for (int i = 0; i < testValues.length; i++) {
assertEquals(resultValues[i], MathUtils.nextPowerOf2(testValues[i]));
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论