MathHelper

Members

Static functions

abs
int abs(int a)

Returns the absolute value of an {@code int} value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

abs
long abs(long a)

Returns the absolute value of a {@code long} value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.

abs
float abs(float a)

Returns the absolute value of a {@code float} value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. Special cases: <ul><li>If the argument is positive zero or negative zero, the result is positive zero. <li>If the argument is infinite, the result is positive infinity. <li>If the argument is NaN, the result is NaN.</ul>

abs
double abs(double a)

Returns the absolute value of a {@code double} value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned. Special cases: <ul><li>If the argument is positive zero or negative zero, the result is positive zero. <li>If the argument is infinite, the result is positive infinity. <li>If the argument is NaN, the result is NaN.</ul>

addExact
int addExact(int x, int y)

Returns the sum of its arguments, throwing an exception if the result overflows an {@code int}.

addExact
long addExact(long x, long y)

Returns the sum of its arguments, throwing an exception if the result overflows a {@code long}.

ceil
double ceil(double a)

Returns the smallest (closest to negative infinity) {@code double} value that is greater than or equal to the argument and is equal to a mathematical integer. Special cases: <ul><li>If the argument value is already equal to a mathematical integer, then the result is the same as the argument. <li>If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument. <li>If the argument value is less than zero but greater than -1.0, then the result is negative zero.</ul> Note that the value of {@code Math.ceil(x)} is exactly the value of {@code -Math.floor(-x)}.

decrementExact
int decrementExact(int a)

Returns the argument decremented by one, throwing an exception if the result overflows an {@code int}.

decrementExact
long decrementExact(long a)

Returns the argument decremented by one, throwing an exception if the result overflows a {@code long}.

floor
double floor(double a)

Returns the largest (closest to positive infinity) {@code double} value that is less than or equal to the argument and is equal to a mathematical integer. Special cases: <ul><li>If the argument value is already equal to a mathematical integer, then the result is the same as the argument. <li>If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.</ul>

floorDiv
int floorDiv(int x, int y)

Returns the largest (closest to positive infinity) {@code int} value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the {@linkplain Integer#MIN_VALUE Integer.MIN_VALUE} and the divisor is {@code -1}, then integer overflow occurs and the result is equal to {@code Integer.MIN_VALUE}. <p> Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results from truncation when the exact result is negative. <ul> <li>If the signs of the arguments are the same, the results of {@code floorDiv} and the {@code /} operator are the same. <br> For example, {@code floorDiv(4, 3) == 1} and {@code (4 / 3) == 1}.</li> <li>If the signs of the arguments are different, the quotient is negative and {@code floorDiv} returns the integer less than or equal to the quotient and the {@code /} operator returns the integer closest to zero.<br> For example, {@code floorDiv(-4, 3) == -2}, whereas {@code (-4 / 3) == -1}. </li> </ul>

floorDiv
long floorDiv(long x, int y)

Returns the largest (closest to positive infinity) {@code long} value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1}, then integer overflow occurs and the result is equal to {@code Long.MIN_VALUE}. <p> Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results from truncation when the exact result is negative. <p> For examples, see {@link #floorDiv(int, int)}.

floorDiv
long floorDiv(long x, long y)

Returns the largest (closest to positive infinity) {@code long} value that is less than or equal to the algebraic quotient. There is one special case, if the dividend is the {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1}, then integer overflow occurs and the result is equal to {@code Long.MIN_VALUE}. <p> Normal integer division operates under the round to zero rounding mode (truncation). This operation instead acts under the round toward negative infinity (floor) rounding mode. The floor rounding mode gives different results from truncation when the exact result is negative. <p> For examples, see {@link #floorDiv(int, int)}.

floorMod
int floorMod(int x, int y)

Returns the floor modulus of the {@code int} arguments. <p> The floor modulus is {@code x - (floorDiv(x, y) * y)}, has the same sign as the divisor {@code y}, and is in the range of {@code -abs(y) < r < +abs(y)}.

floorMod
int floorMod(long x, int y)

Returns the floor modulus of the {@code long} and {@code int} arguments. <p> The floor modulus is {@code x - (floorDiv(x, y) * y)}, has the same sign as the divisor {@code y}, and is in the range of {@code -abs(y) < r < +abs(y)}.

floorMod
long floorMod(long x, long y)

Returns the floor modulus of the {@code long} arguments. <p> The floor modulus is {@code x - (floorDiv(x, y) * y)}, has the same sign as the divisor {@code y}, and is in the range of {@code -abs(y) < r < +abs(y)}.

incrementExact
int incrementExact(int a)

Returns the argument incremented by one, throwing an exception if the result overflows an {@code int}.

incrementExact
long incrementExact(long a)

Returns the argument incremented by one, throwing an exception if the result overflows a {@code long}.

max
int max(int a, int b)

Returns the greater of two {@code int} values. That is, the result is the argument closer to the value of {@link Integer#MAX_VALUE}. If the arguments have the same value, the result is that same value.

max
long max(long a, long b)

Returns the greater of two {@code long} values. That is, the result is the argument closer to the value of {@link Long#MAX_VALUE}. If the arguments have the same value, the result is that same value.

max
float max(float a, float b)

Returns the greater of two {@code float} values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.

max
double max(double a, double b)

Returns the greater of two {@code double} values. That is, the result is the argument closer to positive infinity. If the arguments have the same value, the result is that same value. If either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero. If one argument is positive zero and the other negative zero, the result is positive zero.

min
int min(int a, int b)

Returns the smaller of two {@code int} values. That is, the result the argument closer to the value of {@link Integer#MIN_VALUE}. If the arguments have the same value, the result is that same value.

min
long min(long a, long b)

Returns the smaller of two {@code long} values. That is, the result is the argument closer to the value of {@link Long#MIN_VALUE}. If the arguments have the same value, the result is that same value.

multiplyExact
int multiplyExact(int x, int y)

Returns the product of the arguments, throwing an exception if the result overflows an {@code int}.

multiplyExact
long multiplyExact(long x, int y)

Returns the product of the arguments, throwing an exception if the result overflows a {@code long}.

multiplyExact
long multiplyExact(long x, long y)

Returns the product of the arguments, throwing an exception if the result overflows a {@code long}.

multiplyFull
long multiplyFull(int x, int y)

Returns the exact mathematical product of the arguments.

multiplyHigh
long multiplyHigh(long x, long y)

Returns as a {@code long} the most significant 64 bits of the 128-bit product of two 64-bit factors.

negateExact
int negateExact(int a)

Returns the negation of the argument, throwing an exception if the result overflows an {@code int}.

negateExact
long negateExact(long a)

Returns the negation of the argument, throwing an exception if the result overflows a {@code long}.

subtractExact
int subtractExact(int x, int y)

Returns the difference of the arguments, throwing an exception if the result overflows an {@code int}.

subtractExact
long subtractExact(long x, long y)

Returns the difference of the arguments, throwing an exception if the result overflows a {@code long}.

toIntExact
int toIntExact(long value)

Returns the value of the {@code long} argument; throwing an exception if the value overflows an {@code int}.

Variables

E
enum double E;

The {@code double} value that is closer than any other to <i>e</i>, the base of the natural logarithms.

PI
enum double PI;

The {@code double} value that is closer than any other to <i>pi</i>, the ratio of the circumference of a circle to its diameter.

Meta