MovingBlocks/Terasology — pull request #885 by LinusVanElswijk (2014-01-31 13:24:26+00:00)
Title: TeraMath isPowerOfTwo and CeilPowerOfTwo

This pull request contains a suggestion for an alternative isPowerOfTwo implementation and
partly fixes the ceilPowerOfTwo function.
TeraMath tests are included.

The TeraMath.isPowerOfTwo uses the CeilPowerOfTwo function to check if this changes the value.
* This produces true when the input is 0, while 0 is not a power of 2.
* This produced true when the input is Integer.MIN_VALUE
* There exists a faster, bitwise method to check if an int is a power of 2.

The TeraMath.ceilPowerOfTwo
* produces Integer.MIN_VALUE on the input Integer.MIN_VALUE, while the javadoc says it should return 0.
* produces Integer.MIN_VALUE for inputs larger than the largest power of two that fits in an int.

All issues with Integer.MIN_VALUE may be correct behavior if the input should interpreted as unsigned, but than this should be made clear in some way (javadoc or function name).

I included two types of test for the power of two function: a fast one, based on boundary values, and a slow one that tests all inputs. My suggestion would be to remove the slow variants, because I don't think they add any value and just slow things down.