Math

object Math

Properties

Link copied to clipboard
const val E: Double = 2.718281828459045

The double value that is closer than any other to e, the base of the natural logarithms.

Link copied to clipboard
const val PI: Double = 3.141592653589793

The double value that is closer than any other to pi (), the ratio of the circumference of a circle to its diameter.

Link copied to clipboard
val TAU: Double

The double value that is closer than any other to tau (), the ratio of the circumference of a circle to its radius.

Functions

Link copied to clipboard
fun addExact(x: Int, y: Int): Int

Returns the sum of its arguments, throwing an exception if the result overflows an int.

fun addExact(x: Long, y: Long): Long

ported from Math.addExact

Link copied to clipboard
fun ceilDiv(x: Int, y: Int): Int

Returns the smallest (closest to negative infinity) int value that is greater than or equal to the algebraic quotient. There is one special case: if the dividend is Integer.MIN_VALUE and the divisor is -1, then integer overflow occurs and the result is equal to Integer.MIN_VALUE.

Link copied to clipboard
fun floorMod(x: Long, y: Long): Long

Returns the floor modulus of the long arguments.

Link copied to clipboard

Returns the unbiased exponent used in the representation of a double. Special cases:

Returns the unbiased exponent used in the representation of a float. Special cases:

Link copied to clipboard
fun multiplyExact(x: Int, y: Int): Int

Returns the product of the arguments, throwing an exception if the result overflows an int.

Returns the product of the arguments, throwing an exception if the result overflows a long.

Link copied to clipboard
fun nextAfter(start: Double, direction: Double): Double

Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal the second argument is returned.

fun nextAfter(start: Float, direction: Double): Float

Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal a value equivalent to the second argument is returned.

Link copied to clipboard

Returns the floating-point value adjacent to f in the direction of negative infinity. This method is semantically equivalent to nextAfter(f, Float.NEGATIVE_INFINITY); however, a nextDown implementation may run faster than its equivalent nextAfter call.

Link copied to clipboard

fun nextUp(f: Float): Float

Returns the floating-point value adjacent to f in the direction of positive infinity. This method is semantically equivalent to nextAfter(f, Float.POSITIVE_INFINITY); however, a nextUp implementation may run faster than its equivalent nextAfter call.

Link copied to clipboard

Returns a floating-point power of two in the normal range.

Link copied to clipboard
fun round(a: Double): Long

Returns the closest long to the argument, with ties rounding to positive infinity.

fun round(a: Float): Int

Returns the closest int to the argument, with ties rounding to positive infinity.

Link copied to clipboard
fun scalb(d: Double, scaleFactorInput: Int): Double

Multiplies this by 2^scaleFactor with the same edge-case semantics as Math.scalb (IEEE 754 scaleB operation). The implementation is a direct Kotlin port of the JDK algorithm. It guarantees:

Link copied to clipboard
fun toDegrees(angrad: Double): Double

Converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.

Link copied to clipboard
fun toIntExact(value: Long): Int

ported from Math.toIntExact

Link copied to clipboard
fun toRadians(angdeg: Double): Double

Converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.

Link copied to clipboard
fun ulp(f: Float): Float

Returns the size of an ulp of the argument. An ulp, unit in the last place, of a float value is the positive distance between this floating-point value and the float value next larger in magnitude. Note that for non-NaN x, ulp(-*x*) == ulp(*x*).