public class MathUtil
extends java.lang.Object
Constructor and Description |
---|
MathUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
nonNegativeAbs(int a)
Returns the closest non-negative
int value to the absolute value of a . |
public static int nonNegativeAbs(int a)
int
value to the absolute value of a
. Works the same way as Math.abs(int)
for all values except Integer.MIN_VALUE
,
for which Math.abs(int)
returns negative value but this method returns Integer.MAX_VALUE
.
Use this method instead of the standard one
if it's important to get non-negative result and Integer.MIN_VALUE
may be passed as an argument (e.g. if the argument is a result of Object.hashCode()
or Random.nextInt()
call).