MathUtils
public
class
MathUtils
extends Object
| java.lang.Object | |
| ↳ | androidx.core.math.MathUtils |
A utility class providing functions useful for common mathematical operations.
Summary
Public methods | |
|---|---|
static
long
|
addExact(long x, long y)
|
static
int
|
addExact(int x, int y)
|
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
long
|
clamp(long value, long min, long max)
This method takes a numerical value and ensures it fits in a given numerical range. |
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
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
|
decrementExact(long a)
|
static
int
|
decrementExact(int a)
|
static
long
|
incrementExact(long a)
|
static
int
|
incrementExact(int a)
|
static
long
|
multiplyExact(long x, long y)
|
static
int
|
multiplyExact(int x, int y)
|
static
int
|
negateExact(int a)
|
static
long
|
negateExact(long a)
|
static
long
|
subtractExact(long x, long y)
|
static
int
|
subtractExact(int x, int y)
|
static
int
|
toIntExact(long value)
|
Inherited methods | |
|---|---|
Public methods
addExact
public static long addExact (long x,
long y)
See Math.addExact(long, long).
| Parameters | |
|---|---|
x |
long |
y |
long |
| Returns | |
|---|---|
long |
|
addExact
public static int addExact (int x,
int y)
| Parameters | |
|---|---|
x |
int |
y |
int |
| Returns | |
|---|---|
int |
|
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 | |
|---|---|
value |
double: the value to be clamped. |
min |
double: minimum resulting value. |
max |
double: maximum resulting value. |
| Returns | |
|---|---|
double |
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 | |
|---|---|
value |
long: the value to be clamped. |
min |
long: minimum resulting value. |
max |
long: maximum resulting value. |
| Returns | |
|---|---|
long |
the clamped value. |
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 | |
|---|---|
value |
float: the value to be clamped. |
min |
float: minimum resulting value. |
max |
float: maximum resulting value. |
| Returns | |
|---|---|
float |
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 | |
|---|---|
value |
int: the value to be clamped. |
min |
int: minimum resulting value. |
max |
int: maximum resulting value. |
| Returns | |
|---|---|
int |
the clamped value. |
decrementExact
public static long decrementExact (long a)
See Math.decrementExact(long).
| Parameters | |
|---|---|
a |
long |
| Returns | |
|---|---|
long |
|
decrementExact
public static int decrementExact (int a)
| Parameters | |
|---|---|
a |
int |
| Returns | |
|---|---|
int |
|
incrementExact
public static long incrementExact (long a)
See Math.incrementExact(long).
| Parameters | |
|---|---|
a |
long |
| Returns | |
|---|---|
long |
|
incrementExact
public static int incrementExact (int a)
| Parameters | |
|---|---|
a |
int |
| Returns | |
|---|---|
int |
|
multiplyExact
public static long multiplyExact (long x,
long y)
See Math.multiplyExact(long, long).
| Parameters | |
|---|---|
x |
long |
y |
long |
| Returns | |
|---|---|
long |
|
multiplyExact
public static int multiplyExact (int x,
int y)
See Math.multiplyExact(int, int).
| Parameters | |
|---|---|
x |
int |
y |
int |
| Returns | |
|---|---|
int |
|
negateExact
public static int negateExact (int a)
| Parameters | |
|---|---|
a |
int |
| Returns | |
|---|---|
int |
|
negateExact
public static long negateExact (long a)
| Parameters | |
|---|---|
a |
long |
| Returns | |
|---|---|
long |
|
subtractExact
public static long subtractExact (long x,
long y)
See Math.subtractExact(long, long).
| Parameters | |
|---|---|
x |
long |
y |
long |
| Returns | |
|---|---|
long |
|
subtractExact
public static int subtractExact (int x,
int y)
See Math.subtractExact(int, int).
| Parameters | |
|---|---|
x |
int |
y |
int |
| Returns | |
|---|---|
int |
|
toIntExact
public static int toIntExact (long value)
| Parameters | |
|---|---|
value |
long |
| Returns | |
|---|---|
int |
|