MathUtils
class MathUtils
A utility class providing functions useful for common mathematical operations.
Summary
Public functions |
|
|---|---|
java-static Int |
Returns the sum of its arguments, throwing an exception if the result overflows an |
java-static Long |
Returns the sum of its arguments, throwing an exception if the result overflows a |
java-static Double |
This method takes a numerical value and ensures it fits in a given numerical range. |
java-static Float |
This method takes a numerical value and ensures it fits in a given numerical range. |
java-static Int |
This method takes a numerical value and ensures it fits in a given numerical range. |
java-static Long |
This method takes a numerical value and ensures it fits in a given numerical range. |
java-static Int |
decrementExact(a: Int)Returns the argument decremented by one, throwing an exception if the result overflows an |
java-static Long |
decrementExact(a: Long)Returns the argument decremented by one, throwing an exception if the result overflows a |
java-static Int |
incrementExact(a: Int)Returns the argument incremented by one, throwing an exception if the result overflows an |
java-static Long |
incrementExact(a: Long)Returns the argument incremented by one, throwing an exception if the result overflows a |
java-static Int |
multiplyExact(x: Int, y: Int)Returns the product of the arguments, throwing an exception if the result overflows an |
java-static Long |
multiplyExact(x: Long, y: Long)Returns the product of the arguments, throwing an exception if the result overflows a |
java-static Int |
negateExact(a: Int)Returns the negation of the argument, throwing an exception if the result overflows an |
java-static Long |
negateExact(a: Long)Returns the negation of the argument, throwing an exception if the result overflows a |
java-static Int |
subtractExact(x: Int, y: Int)Returns the difference of the arguments, throwing an exception if the result overflows an |
java-static Long |
subtractExact(x: Long, y: Long)Returns the difference of the arguments, throwing an exception if the result overflows a |
java-static Int |
toIntExact(value: Long)Returns the value of the |
Public functions
addExact
java-static fun addExact(x: Int, y: Int): Int
Returns the sum of its arguments, throwing an exception if the result overflows an int.
| Returns | |
|---|---|
Int |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows an int |
addExact
java-static fun addExact(x: Long, y: Long): Long
Returns the sum of its arguments, throwing an exception if the result overflows a long.
| Returns | |
|---|---|
Long |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows a long |
clamp
java-static fun clamp(value: Double, min: Double, max: Double): Double
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
java-static fun clamp(value: Float, min: Float, max: Float): Float
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
java-static fun clamp(value: Int, min: Int, max: Int): Int
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. |
clamp
java-static fun clamp(value: Long, min: Long, max: Long): Long
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. |
decrementExact
java-static fun decrementExact(a: Int): Int
Returns the argument decremented by one, throwing an exception if the result overflows an int. The overflow only occurs for the minimum value.
| Parameters | |
|---|---|
a: Int |
the value to decrement |
| Returns | |
|---|---|
Int |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows an int |
decrementExact
java-static fun decrementExact(a: Long): Long
Returns the argument decremented by one, throwing an exception if the result overflows a long. The overflow only occurs for the minimum value.
| Parameters | |
|---|---|
a: Long |
the value to decrement |
| Returns | |
|---|---|
Long |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows a long |
incrementExact
java-static fun incrementExact(a: Int): Int
Returns the argument incremented by one, throwing an exception if the result overflows an int. The overflow only occurs for the maximum value.
| Parameters | |
|---|---|
a: Int |
the value to increment |
| Returns | |
|---|---|
Int |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows an int |
incrementExact
java-static fun incrementExact(a: Long): Long
Returns the argument incremented by one, throwing an exception if the result overflows a long. The overflow only occurs for the maximum value.
| Parameters | |
|---|---|
a: Long |
the value to increment |
| Returns | |
|---|---|
Long |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows a long |
multiplyExact
java-static fun multiplyExact(x: Int, y: Int): Int
Returns the product of the arguments, throwing an exception if the result overflows an int.
| Returns | |
|---|---|
Int |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows an int |
multiplyExact
java-static fun multiplyExact(x: Long, y: Long): Long
Returns the product of the arguments, throwing an exception if the result overflows a long.
| Returns | |
|---|---|
Long |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows a long |
negateExact
java-static fun negateExact(a: Int): Int
Returns the negation of the argument, throwing an exception if the result overflows an int. The overflow only occurs for the minimum value.
| Parameters | |
|---|---|
a: Int |
the value to negate |
| Returns | |
|---|---|
Int |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows an int |
negateExact
java-static fun negateExact(a: Long): Long
Returns the negation of the argument, throwing an exception if the result overflows a long. The overflow only occurs for the minimum value.
| Parameters | |
|---|---|
a: Long |
the value to negate |
| Returns | |
|---|---|
Long |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows a long |
subtractExact
java-static fun subtractExact(x: Int, y: Int): Int
Returns the difference of the arguments, throwing an exception if the result overflows an int.
| Returns | |
|---|---|
Int |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows an int |
subtractExact
java-static fun subtractExact(x: Long, y: Long): Long
Returns the difference of the arguments, throwing an exception if the result overflows a long.
| Returns | |
|---|---|
Long |
the result |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the result overflows a long |
toIntExact
java-static fun toIntExact(value: Long): Int
Returns the value of the long argument, throwing an exception if the value overflows an int.
| Parameters | |
|---|---|
value: Long |
the long value |
| Returns | |
|---|---|
Int |
the argument as an int |
| Throws | |
|---|---|
java.lang.ArithmeticException |
if the |