MathUtils

open class MathUtils(source)

A utility class providing functions useful for common mathematical operations.

Functions

Link copied to clipboard
open fun addExact(x: Int, y: Int): Int
Returns the sum of its arguments, throwing an exception if the result overflows an int.
open fun addExact(x: Long, y: Long): Long
Returns the sum of its arguments, throwing an exception if the result overflows a long.
Link copied to clipboard
open fun clamp(value: Double, min: Double, max: Double): Double
open fun clamp(value: Float, min: Float, max: Float): Float
open fun clamp(value: Int, min: Int, max: Int): Int
open fun clamp(value: Long, min: Long, max: Long): Long
This method takes a numerical value and ensures it fits in a given numerical range.
Link copied to clipboard
open fun decrementExact(a: Int): Int
Returns the argument decremented by one, throwing an exception if the result overflows an int.
open fun decrementExact(a: Long): Long
Returns the argument decremented by one, throwing an exception if the result overflows a long.
Link copied to clipboard
open fun incrementExact(a: Int): Int
Returns the argument incremented by one, throwing an exception if the result overflows an int.
open fun incrementExact(a: Long): Long
Returns the argument incremented by one, throwing an exception if the result overflows a long.
Link copied to clipboard
open fun multiplyExact(x: Int, y: Int): Int
Returns the product of the arguments, throwing an exception if the result overflows an int.
open fun multiplyExact(x: Long, y: Long): Long
Returns the product of the arguments, throwing an exception if the result overflows a long.
Link copied to clipboard
open fun negateExact(a: Int): Int
Returns the negation of the argument, throwing an exception if the result overflows an int.
open fun negateExact(a: Long): Long
Returns the negation of the argument, throwing an exception if the result overflows a long.
Link copied to clipboard
open fun subtractExact(x: Int, y: Int): Int
Returns the difference of the arguments, throwing an exception if the result overflows an int.
open fun subtractExact(x: Long, y: Long): Long
Returns the difference of the arguments, throwing an exception if the result overflows a long.
Link copied to clipboard
open fun toIntExact(value: Long): Int
Returns the value of the long argument, throwing an exception if the value overflows an int.