public class MathUtils extends Object
Constructor and Description |
---|
MathUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
addSafely(int a,
int b)
Safely add the given int value by another int value, ensuring that no overflow occurs.
|
static int |
incrementSafely(int a)
Safely increments the given int value by one, ensuring that no overflow occurs.
|
static boolean |
isPowerOf2(long value)
Checks whether the given value is a power of two.
|
static int |
log2strict(int value)
Computes the logarithm of the given value to the base of 2.
|
static Integer |
max(Integer v1,
Integer v2) |
static Integer |
min(Integer v1,
Integer v2) |
static int |
roundDownToPowerOf2(int value)
Decrements the given number down to the closest power of two.
|
public static int roundDownToPowerOf2(int value)
value
- The value to round down.public static boolean isPowerOf2(long value)
value
- The value to check.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 incrementSafely(int a)
public static int addSafely(int a, int b)
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.