Package kotlin.math

Mathematical functions and constants.

The functions include trigonometric, hyperbolic, exponentiation and power, logarithmic, rounding, sign and absolute value.

Functions

abs
Link copied to clipboard
fun abs(x: Double): Double
fun abs(x: Float): Float
inline fun abs(x: Double): Double
inline fun abs(x: Float): Float
inline fun abs(x: Double): Double
inline fun abs(x: Float): Float
external fun abs(x: Double): Double
external fun abs(x: Float): Float

Returns the absolute value of the given value x.

Since Kotlin

1.2
fun abs(n: Int): Int
fun abs(n: Long): Long
inline fun abs(n: Int): Int
inline fun abs(n: Long): Long
fun abs(n: Int): Int
fun abs(n: Long): Long
external fun abs(n: Int): Int
external fun abs(n: Long): Long

Returns the absolute value of the given value n.

Since Kotlin

1.2
acos
Link copied to clipboard
fun acos(x: Double): Double
fun acos(x: Float): Float
inline fun acos(x: Double): Double
inline fun acos(x: Float): Float
inline fun acos(x: Double): Double
inline fun acos(x: Float): Float
external fun acos(x: Double): Double
external fun acos(x: Float): Float

Computes the arc cosine of the value x; the returned value is an angle in the range from 0.0 to PI radians.

Since Kotlin

1.2
acosh
Link copied to clipboard
fun acosh(x: Double): Double
fun acosh(x: Float): Float
fun acosh(x: Double): Double
inline fun acosh(x: Float): Float
inline fun acosh(x: Double): Double
inline fun acosh(x: Float): Float
external fun acosh(x: Double): Double
external fun acosh(x: Float): Float

Computes the inverse hyperbolic cosine of the value x.

Since Kotlin

1.2
asin
Link copied to clipboard
fun asin(x: Double): Double
fun asin(x: Float): Float
inline fun asin(x: Double): Double
inline fun asin(x: Float): Float
inline fun asin(x: Double): Double
inline fun asin(x: Float): Float
external fun asin(x: Double): Double
external fun asin(x: Float): Float

Computes the arc sine of the value x; the returned value is an angle in the range from -PI/2 to PI/2 radians.

Since Kotlin

1.2
asinh
Link copied to clipboard
fun asinh(x: Double): Double
fun asinh(x: Float): Float
fun asinh(x: Double): Double
inline fun asinh(x: Float): Float
inline fun asinh(x: Double): Double
inline fun asinh(x: Float): Float
external fun asinh(x: Double): Double
external fun asinh(x: Float): Float

Computes the inverse hyperbolic sine of the value x.

Since Kotlin

1.2
atan
Link copied to clipboard
fun atan(x: Double): Double
fun atan(x: Float): Float
inline fun atan(x: Double): Double
inline fun atan(x: Float): Float
inline fun atan(x: Double): Double
inline fun atan(x: Float): Float
external fun atan(x: Double): Double
external fun atan(x: Float): Float

Computes the arc tangent of the value x; the returned value is an angle in the range from -PI/2 to PI/2 radians.

Since Kotlin

1.2
atan2
Link copied to clipboard
fun atan2(y: Double, x: Double): Double
fun atan2(y: Float, x: Float): Float
inline fun atan2(y: Double, x: Double): Double
inline fun atan2(y: Float, x: Float): Float
inline fun atan2(y: Double, x: Double): Double
inline fun atan2(y: Float, x: Float): Float
external fun atan2(y: Double, x: Double): Double
external fun atan2(y: Float, x: Float): Float

Returns the angle theta of the polar coordinates (r, theta) that correspond to the rectangular coordinates (x, y) by computing the arc tangent of the value y / x; the returned value is an angle in the range from -PI to PI radians.

Since Kotlin

1.2
atanh
Link copied to clipboard
fun atanh(x: Double): Double
fun atanh(x: Float): Float
fun atanh(x: Double): Double
inline fun atanh(x: Float): Float
inline fun atanh(x: Double): Double
inline fun atanh(x: Float): Float
external fun atanh(x: Double): Double
external fun atanh(x: Float): Float

Computes the inverse hyperbolic tangent of the value x.

Since Kotlin

1.2
ceil
Link copied to clipboard
fun ceil(x: Double): Double
fun ceil(x: Float): Float
inline fun ceil(x: Double): Double
inline fun ceil(x: Float): Float
inline fun ceil(x: Double): Double
inline fun ceil(x: Float): Float
external fun ceil(x: Double): Double
external fun ceil(x: Float): Float

Rounds the given value x to an integer towards positive infinity.

Since Kotlin

1.2
cos
Link copied to clipboard
fun cos(x: Double): Double
fun cos(x: Float): Float
inline fun cos(x: Double): Double
inline fun cos(x: Float): Float
inline fun cos(x: Double): Double
inline fun cos(x: Float): Float
external fun cos(x: Double): Double
external fun cos(x: Float): Float

Computes the cosine of the angle x given in radians.

Since Kotlin

1.2
cosh
Link copied to clipboard
fun cosh(x: Double): Double
fun cosh(x: Float): Float
inline fun cosh(x: Double): Double
inline fun cosh(x: Float): Float
inline fun cosh(x: Double): Double
inline fun cosh(x: Float): Float
external fun cosh(x: Double): Double
external fun cosh(x: Float): Float

Computes the hyperbolic cosine of the value x.

Since Kotlin

1.2
exp
Link copied to clipboard
fun exp(x: Double): Double
fun exp(x: Float): Float
inline fun exp(x: Double): Double
inline fun exp(x: Float): Float
inline fun exp(x: Double): Double
inline fun exp(x: Float): Float
external fun exp(x: Double): Double
external fun exp(x: Float): Float

Computes Euler's number e raised to the power of the value x.

Since Kotlin

1.2
expm1
Link copied to clipboard
fun expm1(x: Double): Double
fun expm1(x: Float): Float
inline fun expm1(x: Double): Double
inline fun expm1(x: Float): Float
inline fun expm1(x: Double): Double
inline fun expm1(x: Float): Float
external fun expm1(x: Double): Double
external fun expm1(x: Float): Float

Computes exp(x) - 1.

Since Kotlin

1.2
floor
Link copied to clipboard
fun floor(x: Double): Double
fun floor(x: Float): Float
inline fun floor(x: Double): Double
inline fun floor(x: Float): Float
inline fun floor(x: Double): Double
inline fun floor(x: Float): Float
external fun floor(x: Double): Double
external fun floor(x: Float): Float

Rounds the given value x to an integer towards negative infinity.

Since Kotlin

1.2
hypot
Link copied to clipboard
fun hypot(x: Double, y: Double): Double
fun hypot(x: Float, y: Float): Float
inline fun hypot(x: Double, y: Double): Double
inline fun hypot(x: Float, y: Float): Float
inline fun hypot(x: Double, y: Double): Double
inline fun hypot(x: Float, y: Float): Float
external fun hypot(x: Double, y: Double): Double
external fun hypot(x: Float, y: Float): Float

Computes sqrt(x^2 + y^2) without intermediate overflow or underflow.

Since Kotlin

1.2
IEEErem
Link copied to clipboard
inline fun Double.IEEErem(divisor: Double): Double
inline fun Float.IEEErem(divisor: Float): Float

Computes the remainder of division of this value by the divisor value according to the IEEE 754 standard.

Since Kotlin

1.2
Native
external fun Double.IEEErem(divisor: Double): Double
external fun Float.IEEErem(divisor: Float): Float

Computes the remainder of division of this value by the divisor value according to the IEEE 754 standard.

Since Kotlin

1.2
ln
Link copied to clipboard
fun ln(x: Double): Double
fun ln(x: Float): Float
inline fun ln(x: Double): Double
inline fun ln(x: Float): Float
inline fun ln(x: Double): Double
inline fun ln(x: Float): Float
external fun ln(x: Double): Double
external fun ln(x: Float): Float

Computes the natural logarithm (base E) of the value x.

Since Kotlin

1.2
ln1p
Link copied to clipboard
fun ln1p(x: Double): Double
inline fun ln1p(x: Double): Double
inline fun ln1p(x: Double): Double
external fun ln1p(x: Double): Double

Computes ln(x + 1).

Since Kotlin

1.2
fun ln1p(x: Float): Float
inline fun ln1p(x: Float): Float
inline fun ln1p(x: Float): Float
external fun ln1p(x: Float): Float

Computes ln(a + 1).

Since Kotlin

1.2
log
Link copied to clipboard
fun log(x: Double, base: Double): Double
fun log(x: Float, base: Float): Float
fun log(x: Double, base: Double): Double
fun log(x: Float, base: Float): Float
fun log(x: Double, base: Double): Double
inline fun log(x: Float, base: Float): Float
fun log(x: Double, base: Double): Double
fun log(x: Float, base: Float): Float

Computes the logarithm of the value x to the given base.

Since Kotlin

1.2
log10
Link copied to clipboard
fun log10(x: Double): Double
fun log10(x: Float): Float
inline fun log10(x: Double): Double
inline fun log10(x: Float): Float
inline fun log10(x: Double): Double
inline fun log10(x: Float): Float
external fun log10(x: Double): Double
external fun log10(x: Float): Float

Computes the common logarithm (base 10) of the value x.

Since Kotlin

1.2
log2
Link copied to clipboard
fun log2(x: Double): Double
fun log2(x: Float): Float
fun log2(x: Double): Double
fun log2(x: Float): Float
inline fun log2(x: Double): Double
inline fun log2(x: Float): Float
external fun log2(x: Double): Double
external fun log2(x: Float): Float

Computes the binary logarithm (base 2) of the value x.

Since Kotlin

1.2
max
Link copied to clipboard
fun max(a: Double, b: Double): Double
fun max(a: Float, b: Float): Float
fun max(a: Int, b: Int): Int
fun max(a: Long, b: Long): Long
inline fun max(a: Double, b: Double): Double
inline fun max(a: Float, b: Float): Float
inline fun max(a: Int, b: Int): Int
inline fun max(a: Long, b: Long): Long
inline fun max(a: Double, b: Double): Double
inline fun max(a: Float, b: Float): Float
inline fun max(a: Int, b: Int): Int
inline fun max(a: Long, b: Long): Long
fun max(a: Double, b: Double): Double
fun max(a: Float, b: Float): Float
fun max(a: Int, b: Int): Int
fun max(a: Long, b: Long): Long

Returns the greater of two values.

Since Kotlin

1.2
Common
inline fun max(a: UInt, b: UInt): UInt
inline fun max(a: ULong, b: ULong): ULong

Returns the greater of two values.

Since Kotlin

1.5
min
Link copied to clipboard
fun min(a: Double, b: Double): Double
fun min(a: Float, b: Float): Float
fun min(a: Int, b: Int): Int
fun min(a: Long, b: Long): Long
inline fun min(a: Double, b: Double): Double
inline fun min(a: Float, b: Float): Float
inline fun min(a: Int, b: Int): Int
inline fun min(a: Long, b: Long): Long
inline fun min(a: Double, b: Double): Double
inline fun min(a: Float, b: Float): Float
inline fun min(a: Int, b: Int): Int
inline fun min(a: Long, b: Long): Long
fun min(a: Double, b: Double): Double
fun min(a: Float, b: Float): Float
fun min(a: Int, b: Int): Int
fun min(a: Long, b: Long): Long

Returns the smaller of two values.

Since Kotlin

1.2
Common
inline fun min(a: UInt, b: UInt): UInt
inline fun min(a: ULong, b: ULong): ULong

Returns the smaller of two values.

Since Kotlin

1.5
nextDown
Link copied to clipboard
Common
fun Double.nextDown(): Double

Returns the Double value nearest to this value in direction of negative infinity.

Since Kotlin

1.2
inline fun Double.nextDown(): Double

Returns the Double value nearest to this value in direction of negative infinity.

Since Kotlin

1.2
JS
fun Double.nextDown(): Double

Returns the Double value nearest to this value in direction of negative infinity.

Since Kotlin

1.2
Native
external fun Double.nextDown(): Double

Returns the Double value nearest to this value in direction of negative infinity.

Since Kotlin

1.2
inline fun Float.nextDown(): Float

Returns the Float value nearest to this value in direction of negative infinity.

Since Kotlin

1.2
Native
external fun Float.nextDown(): Float

Returns the Float value nearest to this value in direction of negative infinity.

Since Kotlin

1.2
nextTowards
Link copied to clipboard
Common
fun Double.nextTowards(to: Double): Double

Returns the Double value nearest to this value in direction from this value towards the value to.

Since Kotlin

1.2
inline fun Double.nextTowards(to: Double): Double

Returns the Double value nearest to this value in direction from this value towards the value to.

Since Kotlin

1.2
JS
fun Double.nextTowards(to: Double): Double

Returns the Double value nearest to this value in direction from this value towards the value to.

Since Kotlin

1.2
Native
external fun Double.nextTowards(to: Double): Double

Returns the Double value nearest to this value in direction from this value towards the value to.

Since Kotlin

1.2
inline fun Float.nextTowards(to: Float): Float

Returns the Float value nearest to this value in direction from this value towards the value to.

Since Kotlin

1.2
Native
external fun Float.nextTowards(to: Float): Float

Returns the Float value nearest to this value in direction from this value towards the value to.

Since Kotlin

1.2
nextUp
Link copied to clipboard
Common
fun Double.nextUp(): Double

Returns the Double value nearest to this value in direction of positive infinity.

Since Kotlin

1.2
inline fun Double.nextUp(): Double

Returns the Double value nearest to this value in direction of positive infinity.

Since Kotlin

1.2
JS
fun Double.nextUp(): Double

Returns the Double value nearest to this value in direction of positive infinity.

Since Kotlin

1.2
Native
external fun Double.nextUp(): Double

Returns the Double value nearest to this value in direction of positive infinity.

Since Kotlin

1.2
inline fun Float.nextUp(): Float

Returns the Float value nearest to this value in direction of positive infinity.

Since Kotlin

1.2
Native
external fun Float.nextUp(): Float

Returns the Float value nearest to this value in direction of positive infinity.

Since Kotlin

1.2
pow
Link copied to clipboard
fun Double.pow(x: Double): Double
fun Float.pow(x: Float): Float
inline fun Double.pow(x: Double): Double
inline fun Float.pow(x: Float): Float
inline fun Double.pow(x: Double): Double
inline fun Float.pow(x: Float): Float
external fun Double.pow(x: Double): Double
external fun Float.pow(x: Float): Float

Raises this value to the power x.

Since Kotlin

1.2
fun Double.pow(n: Int): Double
fun Float.pow(n: Int): Float
inline fun Double.pow(n: Int): Double
inline fun Float.pow(n: Int): Float
inline fun Double.pow(n: Int): Double
inline fun Float.pow(n: Int): Float
fun Double.pow(n: Int): Double
fun Float.pow(n: Int): Float

Raises this value to the integer power n.

Since Kotlin

1.2
round
Link copied to clipboard
fun round(x: Double): Double
fun round(x: Float): Float
inline fun round(x: Double): Double
inline fun round(x: Float): Float
fun round(x: Double): Double
inline fun round(x: Float): Float
external fun round(x: Double): Double
external fun round(x: Float): Float

Rounds the given value x towards the closest integer with ties rounded towards even integer.

Since Kotlin

1.2
roundToInt
Link copied to clipboard
Common
fun Double.roundToInt(): Int

Rounds this Double value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
fun Double.roundToInt(): Int

Rounds this Double value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
JS
fun Double.roundToInt(): Int

Rounds this Double value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
Native
fun Double.roundToInt(): Int

Rounds this Double value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
Common
fun Float.roundToInt(): Int

Rounds this Float value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
fun Float.roundToInt(): Int

Rounds this Float value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
JS
inline fun Float.roundToInt(): Int

Rounds this Float value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
Native
fun Float.roundToInt(): Int

Rounds this Float value to the nearest integer and converts the result to Int. Ties are rounded towards positive infinity.

Since Kotlin

1.2
roundToLong
Link copied to clipboard
Common
fun Double.roundToLong(): Long

Rounds this Double value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
fun Double.roundToLong(): Long

Rounds this Double value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
JS
fun Double.roundToLong(): Long

Rounds this Double value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
Native
fun Double.roundToLong(): Long

Rounds this Double value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
Common
fun Float.roundToLong(): Long

Rounds this Float value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
fun Float.roundToLong(): Long

Rounds this Float value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
JS
inline fun Float.roundToLong(): Long

Rounds this Float value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
Native
fun Float.roundToLong(): Long

Rounds this Float value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Since Kotlin

1.2
sign
Link copied to clipboard
fun sign(x: Double): Double
fun sign(x: Float): Float
inline fun sign(x: Double): Double
inline fun sign(x: Float): Float
inline fun sign(x: Double): Double
inline fun sign(x: Float): Float
fun sign(x: Double): Double
fun sign(x: Float): Float

Returns the sign of the given value x:

Since Kotlin

1.2
sin
Link copied to clipboard
fun sin(x: Double): Double
fun sin(x: Float): Float
inline fun sin(x: Double): Double
inline fun sin(x: Float): Float
inline fun sin(x: Double): Double
inline fun sin(x: Float): Float
external fun sin(x: Double): Double
external fun sin(x: Float): Float

Computes the sine of the angle x given in radians.

Since Kotlin

1.2
sinh
Link copied to clipboard
fun sinh(x: Double): Double
fun sinh(x: Float): Float
inline fun sinh(x: Double): Double
inline fun sinh(x: Float): Float
inline fun sinh(x: Double): Double
inline fun sinh(x: Float): Float
external fun sinh(x: Double): Double
external fun sinh(x: Float): Float

Computes the hyperbolic sine of the value x.

Since Kotlin

1.2
sqrt
Link copied to clipboard
fun sqrt(x: Double): Double
fun sqrt(x: Float): Float
inline fun sqrt(x: Double): Double
inline fun sqrt(x: Float): Float
inline fun sqrt(x: Double): Double
inline fun sqrt(x: Float): Float
external fun sqrt(x: Double): Double
external fun sqrt(x: Float): Float

Computes the positive square root of the value x.

Since Kotlin

1.2
tan
Link copied to clipboard
fun tan(x: Double): Double
fun tan(x: Float): Float
inline fun tan(x: Double): Double
inline fun tan(x: Float): Float
inline fun tan(x: Double): Double
inline fun tan(x: Float): Float
external fun tan(x: Double): Double
external fun tan(x: Float): Float

Computes the tangent of the angle x given in radians.

Since Kotlin

1.2
tanh
Link copied to clipboard
fun tanh(x: Double): Double
fun tanh(x: Float): Float
inline fun tanh(x: Double): Double
inline fun tanh(x: Float): Float
inline fun tanh(x: Double): Double
inline fun tanh(x: Float): Float
external fun tanh(x: Double): Double
external fun tanh(x: Float): Float

Computes the hyperbolic tangent of the value x.

Since Kotlin

1.2
truncate
Link copied to clipboard
fun truncate(x: Double): Double
fun truncate(x: Float): Float
fun truncate(x: Double): Double
fun truncate(x: Float): Float
inline fun truncate(x: Double): Double
inline fun truncate(x: Float): Float
fun truncate(x: Double): Double
fun truncate(x: Float): Float

Rounds the given value x to an integer towards zero.

Since Kotlin

1.2
withSign
Link copied to clipboard
fun Double.withSign(sign: Double): Double
fun Double.withSign(sign: Int): Double
fun Float.withSign(sign: Float): Float
fun Float.withSign(sign: Int): Float
inline fun Double.withSign(sign: Double): Double
inline fun Double.withSign(sign: Int): Double
inline fun Float.withSign(sign: Float): Float
inline fun Float.withSign(sign: Int): Float
fun Double.withSign(sign: Double): Double
inline fun Double.withSign(sign: Int): Double
inline fun Float.withSign(sign: Float): Float
inline fun Float.withSign(sign: Int): Float
external fun Double.withSign(sign: Double): Double
fun Double.withSign(sign: Int): Double
external fun Float.withSign(sign: Float): Float
fun Float.withSign(sign: Int): Float

Returns this value with the sign bit same as of the sign value.

Since Kotlin

1.2

Properties

absoluteValue
Link copied to clipboard
val Double.absoluteValue: Double

Returns the absolute value of this value.

val Double.absoluteValue: Double

Returns the absolute value of this value.

val Double.absoluteValue: Double

Returns the absolute value of this value.

val Double.absoluteValue: Double

Returns the absolute value of this value.

absoluteValue
Link copied to clipboard
val Float.absoluteValue: Float

Returns the absolute value of this value.

val Float.absoluteValue: Float

Returns the absolute value of this value.

val Float.absoluteValue: Float

Returns the absolute value of this value.

val Float.absoluteValue: Float

Returns the absolute value of this value.

absoluteValue
Link copied to clipboard
val Int.absoluteValue: Int

Returns the absolute value of this value.

val Int.absoluteValue: Int

Returns the absolute value of this value.

val Int.absoluteValue: Int

Returns the absolute value of this value.

val Int.absoluteValue: Int

Returns the absolute value of this value.

absoluteValue
Link copied to clipboard
val Long.absoluteValue: Long

Returns the absolute value of this value.

val Long.absoluteValue: Long

Returns the absolute value of this value.

val Long.absoluteValue: Long

Returns the absolute value of this value.

val Long.absoluteValue: Long

Returns the absolute value of this value.

E
Link copied to clipboard
Common
const val E: Double = 2.718281828459045

Base of the natural logarithms, approximately 2.71828.

PI
Link copied to clipboard
Common
const val PI: Double = 3.141592653589793

Ratio of the circumference of a circle to its diameter, approximately 3.14159.

sign
Link copied to clipboard
val Double.sign: Double

Returns the sign of this value:

val Double.sign: Double

Returns the sign of this value:

val Double.sign: Double

Returns the sign of this value:

val Double.sign: Double

Returns the sign of this value:

sign
Link copied to clipboard
val Float.sign: Float

Returns the sign of this value:

val Float.sign: Float

Returns the sign of this value:

val Float.sign: Float

Returns the sign of this value:

val Float.sign: Float

Returns the sign of this value:

sign
Link copied to clipboard
val Int.sign: Int

Returns the sign of this value:

val Int.sign: Int

Returns the sign of this value:

val Int.sign: Int

Returns the sign of this value:

val Int.sign: Int

Returns the sign of this value:

sign
Link copied to clipboard
val Long.sign: Int

Returns the sign of this value:

val Long.sign: Int

Returns the sign of this value:

val Long.sign: Int

Returns the sign of this value:

val Long.sign: Int

Returns the sign of this value:

ulp
Link copied to clipboard
val Float.ulp: Float

Returns the ulp of this value.

ulp
Link copied to clipboard
Native
val Float.ulp: Float
ulp
Link copied to clipboard
val Double.ulp: Double

Returns the ulp (unit in the last place) of this value.

val Double.ulp: Double

Returns the ulp (unit in the last place) of this value.

val Double.ulp: Double

Returns the ulp (unit in the last place) of this value.

val Double.ulp: Double

Returns the ulp (unit in the last place) of this value.