Package kotlin.math

Platform and version requirements: Kotlin 1.2

Mathematical functions and constants.

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

Properties

E

const val E: Double

Base of the natural logarithms, approximately 2.71828.

PI

const val PI: Double

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

absoluteValue

actual val Double.absoluteValue: Double
actual val Float.absoluteValue: Float
actual val Int.absoluteValue: Int
actual val Long.absoluteValue: Long

Returns the absolute value of this value.

sign

actual val Double.sign: Double
actual val Float.sign: Float
actual val Int.sign: Int
actual val Long.sign: Int

Returns the sign of this value:

ulp

actual val Double.ulp: Double

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

val Float.ulp: Float

Returns the ulp of this value.

Functions

IEEErem

fun Double.IEEErem(divisor: Double): Double
fun Float.IEEErem(divisor: Float): Float

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

abs

actual fun abs(x: Double): Double
actual fun abs(x: Float): Float

Returns the absolute value of the given value x.

actual fun abs(n: Int): Int
actual fun abs(n: Long): Long

Returns the absolute value of the given value n.

acos

actual fun acos(x: Double): Double
actual 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.

acosh

actual fun acosh(x: Double): Double
actual fun acosh(x: Float): Float

Computes the inverse hyperbolic cosine of the value x.

asin

actual fun asin(x: Double): Double
actual 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.

asinh

actual fun asinh(x: Double): Double
actual fun asinh(x: Float): Float

Computes the inverse hyperbolic sine of the value x.

atan

actual fun atan(x: Double): Double
actual 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.

atan2

actual fun atan2(y: Double, x: Double): Double
actual 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.

atanh

actual fun atanh(x: Double): Double
actual fun atanh(x: Float): Float

Computes the inverse hyperbolic tangent of the value x.

ceil

actual fun ceil(x: Double): Double
actual fun ceil(x: Float): Float

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

cos

actual fun cos(x: Double): Double
actual fun cos(x: Float): Float

Computes the cosine of the angle x given in radians.

cosh

actual fun cosh(x: Double): Double
actual fun cosh(x: Float): Float

Computes the hyperbolic cosine of the value x.

exp

actual fun exp(x: Double): Double
actual fun exp(x: Float): Float

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

expm1

actual fun expm1(x: Double): Double
actual fun expm1(x: Float): Float

Computes exp(x) - 1.

floor

actual fun floor(x: Double): Double
actual fun floor(x: Float): Float

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

hypot

actual fun hypot(x: Double, y: Double): Double
actual fun hypot(x: Float, y: Float): Float

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

ln

actual fun ln(x: Double): Double
actual fun ln(x: Float): Float

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

ln1p

actual fun ln1p(x: Double): Double

Computes ln(x + 1).

actual fun ln1p(x: Float): Float

Computes ln(a + 1).

log

actual fun log(x: Double, base: Double): Double
actual fun log(x: Float, base: Float): Float

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

log10

actual fun log10(x: Double): Double
actual fun log10(x: Float): Float

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

log2

actual fun log2(x: Double): Double
actual fun log2(x: Float): Float

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

max

actual fun max(a: Double, b: Double): Double
actual fun max(a: Float, b: Float): Float
actual fun max(a: Int, b: Int): Int
actual fun max(a: Long, b: Long): Long

Returns the greater of two values.

min

actual fun min(a: Double, b: Double): Double
actual fun min(a: Float, b: Float): Float
actual fun min(a: Int, b: Int): Int
actual fun min(a: Long, b: Long): Long

Returns the smaller of two values.

nextDown

actual fun Double.nextDown(): Double

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

fun Float.nextDown(): Float

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

nextTowards

actual fun Double.nextTowards(to: Double): Double

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

fun Float.nextTowards(to: Float): Float

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

nextUp

actual fun Double.nextUp(): Double

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

fun Float.nextUp(): Float

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

pow

actual fun Double.pow(x: Double): Double
actual fun Float.pow(x: Float): Float

Raises this value to the power x.

actual fun Double.pow(n: Int): Double
actual fun Float.pow(n: Int): Float

Raises this value to the integer power n.

round

actual fun round(x: Double): Double
actual fun round(x: Float): Float

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

roundToInt

actual fun Double.roundToInt(): Int

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

actual fun Float.roundToInt(): Int

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

roundToLong

actual fun Double.roundToLong(): Long

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

actual fun Float.roundToLong(): Long

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

sign

actual fun sign(x: Double): Double
actual fun sign(x: Float): Float

Returns the sign of the given value x:

sin

actual fun sin(x: Double): Double
actual fun sin(x: Float): Float

Computes the sine of the angle x given in radians.

sinh

actual fun sinh(x: Double): Double
actual fun sinh(x: Float): Float

Computes the hyperbolic sine of the value x.

sqrt

actual fun sqrt(x: Double): Double
actual fun sqrt(x: Float): Float

Computes the positive square root of the value x.

tan

actual fun tan(x: Double): Double
actual fun tan(x: Float): Float

Computes the tangent of the angle x given in radians.

tanh

actual fun tanh(x: Double): Double
actual fun tanh(x: Float): Float

Computes the hyperbolic tangent of the value x.

truncate

actual fun truncate(x: Double): Double
actual fun truncate(x: Float): Float

Rounds the given value x to an integer towards zero.

withSign

actual fun Double.withSign(sign: Double): Double
actual fun Double.withSign(sign: Int): Double
actual fun Float.withSign(sign: Float): Float
actual fun Float.withSign(sign: Int): Float

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