Math Methods
CaupolicanDiaz142 total contributions
Published Oct 10, 2023
Contribute to Docs
The Kotlin math
package contains many static methods that provide common mathematical calculations for working with numbers.
These methods can be accessed by importing the package at the top of the file:
import kotlin.math.*
The *
imports all math methods from the kotlin.math
library. To call a specific method, replace the *
with the method name, e.g. kotlin.math.abs
.
Methods
The package includes the following methods:
Math Methods
- .acos()
- Calculates the arccosine, or inverse cosine of a value, returning the angle in radians.
- .tanh()
- Computes the hyperbolic tangent of an angle.
- abs()
- Returns the absolute value of the argument.
- acosh()
- Returns the inverse hyperbolic cosine of a numeric argument.
- asin()
- Returns the arcsine of a numeric argument.
- asinh()
- Returns the inverse hyperbolic sine of a numeric argument.
- atan()
- Returns the arc tangent of a value.
- atan2()
- Calculates the angle between the positive x-axis and a point (x, y) in radians.
- atanh()
- Calculates the inverse hyperbolic tangent of a value.
- cbrt()
- Returns the cube root of the argument.
- ceil()
- Rounds a floating-point number up to the nearest integer.
- cos()
- Calculates the cosine of an angle in radians.
- cosh()
- Computes the hyperbolic cosine of an angle.
- exp()
- Returns e raised to the power of a given number.
- floor()
- Returns the nearest integer that is lower than or equal to the value passed.
- hypot()
- Returns the hypotenuse of two numbers.
- ln()
- Calculates the natural logarithm of a number.
- log()
- Calculates the logarithm of a number with respect to a base value.
- max()
- Finds the greater of two given values.
- min()
- Determines the smaller of two Number values.
- pow()
- Calculates a number raised to the power of another number.
- round()
- Rounds a given number to the nearest integer.
- sin()
- Calculates the sine of an angle in radians.
- sinh()
- Calculates the hyperbolic sine of a given number.
- sqrt()
- Calculates the square root of a given number.
- tan()
- Returns the tangent of an angle.
- truncate()
- Rounds a number to the next whole value towards zero.
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.