Math
module Math
The Math module provides standard mathematical constants and functions. All trigonometric functions operate in radians. A Kex Float is always finite, so a domain error (Math.sqrt(-1.0)) or an overflow (Math.exp(1000.0)) raises rather than producing NaN or Infinity — the same rule BEAM enforces, where those two values cannot exist at all.
PI constant
Math.PI : Float Ratio of a circle's circumference to its diameter.
Examples
Math.PI # => 3.141592653589793
sqrt
sqrt(x: Number) -> Float
Square root of x. Raises for negative input, which has no real root.
Parameters
x
Examples
Math.sqrt(9.0) # => 3.0
Math.sqrt(-1.0) # raises: Math.sqrt: undefined result (NaN)
sin
sin(x: Number) -> Float
Sine of x (radians).
Parameters
x
Examples
Math.sin(Math.PI / 2.0) # => 1.0
tan
tan(x: Number) -> Float
Tangent of x (radians).
Parameters
x
Examples
Math.tan(Math.PI / 4.0) # => 1.0
asin
asin(x: Number) -> Float
Inverse sine (arc sine) of x, result in radians.
Parameters
x- must be in [-1, 1]
Examples
Math.asin(1.0) # => 1.5707963267948966
acos
acos(x: Number) -> Float
Inverse cosine (arc cosine) of x, result in radians.
Parameters
x- must be in [-1, 1]
Examples
Math.acos(1.0) # => 0.0
atan
atan(x: Number) -> Float
Inverse tangent (arc tangent) of x, result in radians in (-π/2, π/2).
Parameters
x
Examples
Math.atan(1.0) # => 0.7853981633974483
atan2
atan2(y: Number, x: Number) -> Float
Two-argument arc tangent. Returns the angle of vector (x, y) in (-π, π]. Handles the sign of both arguments to place the result in the correct quadrant.
Parameters
yx
Examples
Math.atan2(1.0, 1.0) # => 0.7853981633974483
Math.atan2(1.0, -1.0) # => 2.356194490192345
log
log(x: Number) -> Float
log(x: Number, base: Number) -> Float
Natural logarithm of x (base e). With two arguments, computes log base base.
Parameters
xbase- (optional)
Examples
Math.log(Math.E) # => 1.0
Math.log(8.0, 2.0) # => 3.0
log10
log10(x: Number) -> Float
Base-10 logarithm of x.
Parameters
x
Examples
Math.log10(1000.0) # => 3.0
exp
exp(x: Number) -> Float
e raised to the power x.
Parameters
x
Examples
Math.exp(1.0) # => 2.718281828459045