Class MathUtils
- java.lang.Object
-
- com.soundicly.jnanoidenhanced.jnanoid.MathUtils
-
public final class MathUtils extends java.lang.ObjectMethods to perform fast log
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisPowerOfTwo(int x)Returnstrueifxrepresents a power of two.static intlog2(int x, java.math.RoundingMode mode)Returns the base-2 logarithm ofx, rounded according to the specified rounding mode.
-
-
-
Method Detail
-
log2
public static int log2(int x, java.math.RoundingMode mode)Returns the base-2 logarithm ofx, rounded according to the specified rounding mode.- Throws:
java.lang.IllegalArgumentException- ifx <= 0java.lang.ArithmeticException- ifmodeisRoundingMode.UNNECESSARYandxis not a power of two
-
isPowerOfTwo
public static boolean isPowerOfTwo(int x)
Returnstrueifxrepresents a power of two.This differs from
Integer.bitCount(x) == 1, becauseInteger.bitCount(Integer.MIN_VALUE) == 1, butInteger.MIN_VALUEis not a power of two.
-
-