public final class MathUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
checkedDownCast(long value)
Casts the given value to a 32 bit integer, if it can be safely done.
|
static int |
log2floor(int value)
Computes the logarithm of the given value to the base of 2, rounded down.
|
static int |
log2strict(int value)
Computes the logarithm of the given value to the base of 2.
|
static int |
roundDownToPowerOf2(int value)
Decrements the given number down to the closest power of two.
|
public static final int log2floor(int value)
throws ArithmeticException
log2floor(16) = 4, and
log2floor(10) = 3.value - The value to compute the logarithm for.ArithmeticException - Thrown, if the given value is zero.public static final int log2strict(int value)
throws ArithmeticException,
IllegalArgumentException
value - The value to compute the logarithm for.ArithmeticException - Thrown, if the given value is zero.IllegalArgumentException - Thrown, if the given value is not a power of two.public static final int roundDownToPowerOf2(int value)
value - The value to round down.public static final int checkedDownCast(long value)
This method is a protection in places where one expects to be able to safely case, but where unexpected situations could make the cast unsafe and would cause hidden problems that are hard to track down.
value - The value to be cast to an integer.Copyright © 2015 The Apache Software Foundation. All rights reserved.