MathUtils
public class MathUtils
A utility class providing functions useful for common mathematical operations.
Summary
Public constructors |
|
|---|---|
Public methods |
|
|---|---|
static int |
addExact(int x, int y)See |
static long |
addExact(long x, long y)See |
static float |
clamp(float value, float min, float max)This method takes a numerical value and ensures it fits in a given numerical range. |
static double |
clamp(double value, double min, double max)This method takes a numerical value and ensures it fits in a given numerical range. |
static int |
clamp(int value, int min, int max)This method takes a numerical value and ensures it fits in a given numerical range. |
static long |
clamp(long value, long min, long max)This method takes a numerical value and ensures it fits in a given numerical range. |
static int |
decrementExact(int a)See |
static long |
decrementExact(long a)See |
static int |
incrementExact(int a)See |
static long |
incrementExact(long a)See |
static int |
multiplyExact(int x, int y)See |
static long |
multiplyExact(long x, long y)See |
static int |
negateExact(int a)See |
static long |
negateExact(long a)See |
static int |
subtractExact(int x, int y)See |
static long |
subtractExact(long x, long y)See |
static int |
toIntExact(long value)See |
Public constructors
Public methods
clamp
public static float clamp(float value, float min, float max)
This method takes a numerical value and ensures it fits in a given numerical range. If the number is smaller than the minimum required by the range, then the minimum of the range will be returned. If the number is higher than the maximum allowed by the range then the maximum of the range will be returned.
| Parameters | |
|---|---|
float value |
the value to be clamped. |
float min |
minimum resulting value. |
float max |
maximum resulting value. |
| Returns | |
|---|---|
float |
the clamped value. |
clamp
public static double clamp(double value, double min, double max)
This method takes a numerical value and ensures it fits in a given numerical range. If the number is smaller than the minimum required by the range, then the minimum of the range will be returned. If the number is higher than the maximum allowed by the range then the maximum of the range will be returned.
| Parameters | |
|---|---|
double value |
the value to be clamped. |
double min |
minimum resulting value. |
double max |
maximum resulting value. |
| Returns | |
|---|---|
double |
the clamped value. |
clamp
public static int clamp(int value, int min, int max)
This method takes a numerical value and ensures it fits in a given numerical range. If the number is smaller than the minimum required by the range, then the minimum of the range will be returned. If the number is higher than the maximum allowed by the range then the maximum of the range will be returned.
| Parameters | |
|---|---|
int value |
the value to be clamped. |
int min |
minimum resulting value. |
int max |
maximum resulting value. |
| Returns | |
|---|---|
int |
the clamped value. |
clamp
public static long clamp(long value, long min, long max)
This method takes a numerical value and ensures it fits in a given numerical range. If the number is smaller than the minimum required by the range, then the minimum of the range will be returned. If the number is higher than the maximum allowed by the range then the maximum of the range will be returned.
| Parameters | |
|---|---|
long value |
the value to be clamped. |
long min |
minimum resulting value. |
long max |
maximum resulting value. |
| Returns | |
|---|---|
long |
the clamped value. |