Class MathUtilities
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
clamp
(int value, int min, int max) Ensures that the given value is within the given range.static void
static long
unsignedDivide
(long numerator, long denominator) Perform unsigned division.static int
unsignedMax
(int a, int b) Compute the maximum, treating the inputs as unsignedstatic long
unsignedMax
(int a, long b) Compute the maximum, treating the inputs as unsignedstatic long
unsignedMax
(long a, int b) Compute the maximum, treating the inputs as unsignedstatic long
unsignedMax
(long a, long b) Compute the maximum, treating the inputs as unsignedstatic int
unsignedMin
(int a, int b) Compute the minimum, treating the inputs as unsignedstatic int
unsignedMin
(int a, long b) Compute the minimum, treating the inputs as unsignedstatic int
unsignedMin
(long a, int b) Compute the minimum, treating the inputs as unsignedstatic long
unsignedMin
(long a, long b) Compute the minimum, treating the inputs as unsignedstatic long
unsignedModulo
(long numerator, long denominator) Perform unsigned modulo.
-
Method Details
-
unsignedDivide
public static long unsignedDivide(long numerator, long denominator) Perform unsigned division. Provides proper handling of all 64-bit unsigned values.- Parameters:
numerator
- unsigned numeratordenominator
- positive divisor- Returns:
- result of unsigned division
- Throws:
IllegalArgumentException
- if negative denominator is specified
-
unsignedModulo
public static long unsignedModulo(long numerator, long denominator) Perform unsigned modulo. Provides proper handling of all 64-bit unsigned values.- Parameters:
numerator
- unsigned numeratordenominator
- positive divisor- Returns:
- result of unsigned modulo (i.e., remainder)
- Throws:
IllegalArgumentException
- if negative denominator is specified
-
clamp
public static int clamp(int value, int min, int max) Ensures that the given value is within the given range.- Parameters:
value
- the value to checkmin
- the minimum value allowedmax
- the maximum value allowed- Returns:
- the clamped value
-
main
-
unsignedMin
public static long unsignedMin(long a, long b) Compute the minimum, treating the inputs as unsigned- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the minimum
-
unsignedMin
public static int unsignedMin(int a, int b) Compute the minimum, treating the inputs as unsigned- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the minimum
-
unsignedMin
public static int unsignedMin(int a, long b) Compute the minimum, treating the inputs as unsignedThis method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the
int
parameter before performing any comparison. Also note the return type isint
, since b would never be selected if it overflows anint
.- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the minimum
-
unsignedMin
public static int unsignedMin(long a, int b) Compute the minimum, treating the inputs as unsignedThis method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the
int
parameter before performing any comparison. Also note the return type isint
, since b would never be selected if it overflows anint
.- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the minimum
-
unsignedMax
public static long unsignedMax(long a, long b) Compute the maximum, treating the inputs as unsigned- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the maximum
-
unsignedMax
public static int unsignedMax(int a, int b) Compute the maximum, treating the inputs as unsigned- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the maximum
-
unsignedMax
public static long unsignedMax(int a, long b) Compute the maximum, treating the inputs as unsignedThis method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the
int
parameter before performing any comparison.- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the maximum
-
unsignedMax
public static long unsignedMax(long a, int b) Compute the maximum, treating the inputs as unsignedThis method is overloaded to prevent accidental signed-extension on one of the inputs. This method will correctly zero-extend the
int
parameter before performing any comparison.- Parameters:
a
- the first value to considerb
- the second value to consider- Returns:
- the maximum
-