Package io.servicetalk.utils.internal
Class MathUtils
- java.lang.Object
-
- io.servicetalk.utils.internal.MathUtils
-
public final class MathUtils extends java.lang.ObjectInternal math utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intfindNextPositivePowerOfTwo(int value)Fast method of finding the next power of 2 greater than or equal to the supplied value.static intsafeFindNextPositivePowerOfTwo(int value)Fast method of finding the next power of 2 greater than or equal to the supplied value.
-
-
-
Method Detail
-
findNextPositivePowerOfTwo
public static int findNextPositivePowerOfTwo(int value)
Fast method of finding the next power of 2 greater than or equal to the supplied value.If the value is
<= 0then 1 will be returned. This method is not suitable forInteger.MIN_VALUEor numbers greater than 2^30.- Parameters:
value- from which to search for next power of 2- Returns:
- The next power of 2 or the value itself if it is a power of 2
-
safeFindNextPositivePowerOfTwo
public static int safeFindNextPositivePowerOfTwo(int value)
Fast method of finding the next power of 2 greater than or equal to the supplied value.This method will do runtime bounds checking and call
findNextPositivePowerOfTwo(int)if within a valid range.- Parameters:
value- from which to search for next power of 2- Returns:
- The next power of 2 or the value itself if it is a power of 2.
Special cases for return values are as follows:
<= 0to 1>= 2^30to 2^30
-
-