Class MathUtils
java.lang.Object
org.eclipse.jetty.util.MathUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
cappedAdd
(int a, int b, int maxValue) Returns the sum of its arguments, capping tomaxValue
.static long
cappedAdd
(long a, long b) Returns the sum of its arguments, capping toLong.MAX_VALUE
if they overflow.static int
ceilLog2
(int value) Computes binary logarithm of the given number ceiled to the next power of two.static int
ceilToNextPowerOfTwo
(int value) Get the next highest power of twostatic boolean
sumOverflows
(int a, int b) Returns whether the sum of the arguments overflows anint
.
-
Method Details
-
sumOverflows
public static boolean sumOverflows(int a, int b) Returns whether the sum of the arguments overflows anint
.- Parameters:
a
- the first valueb
- the second value- Returns:
- whether the sum of the arguments overflows an
int
-
cappedAdd
public static long cappedAdd(long a, long b) Returns the sum of its arguments, capping toLong.MAX_VALUE
if they overflow.- Parameters:
a
- the first valueb
- the second value- Returns:
- the sum of the values, capped to
Long.MAX_VALUE
-
cappedAdd
public static int cappedAdd(int a, int b, int maxValue) Returns the sum of its arguments, capping tomaxValue
.- Parameters:
a
- the first valueb
- the second value- Returns:
- the sum of the values, capped to
maxValue
-
ceilToNextPowerOfTwo
public static int ceilToNextPowerOfTwo(int value) Get the next highest power of two- Parameters:
value
- An integer- Returns:
- a power of two that is greater than or equal to
value
-
ceilLog2
public static int ceilLog2(int value) Computes binary logarithm of the given number ceiled to the next power of two. If the given number is 800, it is ceiled to 1024 which is the closest power of 2 greater than or equal to 800, then 1024 is 10_000_000_000 in binary, i.e.: 1 followed by 10 zeros, and it's also 2 to the power of 10. So for the numbers between 513 and 1024 the returned value is 10.- Parameters:
value
- An integer- Returns:
- the binary logarithm of the given number ceiled to the next power of two.
-