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 boolean |
isPowerOf2(long value)
Checks whether the given value is a power of two.
|
static int |
jenkinsHash(int code)
This function hashes an integer value.
|
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 |
murmurHash(int code)
This function hashes an integer value.
|
static int |
roundDownToPowerOf2(int value)
Decrements the given number down to the closest power of two.
|
public static 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 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 int roundDownToPowerOf2(int value)
value
- The value to round down.public static 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.public static boolean isPowerOf2(long value)
value
- The value to check.public static int jenkinsHash(int code)
code
- The integer to be hashed.public static int murmurHash(int code)
code
- The integer to be hashed.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.