Add BitShiftUtil square() and pow()

This commit is contained in:
James Seibel
2022-11-06 21:40:21 -06:00
parent 8099925dc2
commit 2429cbbb52
4 changed files with 23 additions and 3 deletions
@@ -32,4 +32,24 @@ public class BitShiftUtil
*/
public static int half(int value) { return value >> 1; }
/**
* Equivalent to: <br>
* value << 1, <br>
* value^2, <br>
* Math.pow(value, 2) <br><br>
*
* Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same.
*/
public static int square(int value) { return value << 1; }
/**
* Equivalent to: <br>
* value << power, <br>
* value^power, <br>
* Math.pow(value, power) <br><br>
*
* Note: Math.pow() isn't identical for large values where bits would be lost in the shift, however for medium to small values they function the same.
*/
public static int pow(int value, int power) { return value << power; }
}