Math Module
The Math module is a standard module that provides common mathematical functions and constants.

Usage
use Math
To access module functions, use the . operator. For example:
Math.sqrt(9) // Returns 3.0
Functions
abs
The abs function returns the absolute value of a number. The absolute value of a number is its magnitude without considering its sign.
Math.abs(-5) // Returns 5
Math.abs(3) // Returns 3
Math.abs(0) // Returns 0
average
The average function calculates the arithmetic mean of a set of numbers.
var numbers = [1, 2, 3, 4, 5]
var avg = Math.average(numbers)
print(avg) // Shows 3
// Also accepts individual parameters
print(Math.average(1, 2, 3, 4, 5)) // Shows 3
ceil
Function that rounds a number up to an integer.
print(Math.ceil(3.14159)) // Shows 4
print(Math.ceil(-3.14159)) // Shows -3
floor
The floor function returns the largest integer that is less than or equal to the given number.
println(Math.floor(4.9)) // Returns 4
println(Math.floor(4.1)) // Returns 4
println(Math.floor(-4.9)) // Returns -5
println(Math.floor(-4.1)) // Returns -5
sqrt
The sqrt function is used to calculate the square root of a number.
result = Math.sqrt(16) // result = 4
round
Function that rounds a number to a specified number of decimal places.
print(Math.round(3.14159)) // Returns 3
print(Math.round(3.14159, 2)) // Returns 3.14
max
Returns the maximum value of the provided parameters.
min
Returns the minimum value of the provided parameters.
Trigonometric Functions
| Function | Description |
|---|---|
sin(x) | Sine of x in radians |
cos(x) | Cosine of x in radians |
tan(x) | Tangent of x in radians |
asin(x) | Arc sine of x in radians |
acos(x) | Arc cosine of x in radians |
atan(x) | Arc tangent of x in radians |
atan2(y, x) | Arc tangent of y/x in radians |
Hyperbolic Functions
| Function | Description |
|---|---|
sinh(x) | Hyperbolic sine of x |
cosh(x) | Hyperbolic cosine of x |
tanh(x) | Hyperbolic tangent of x |
Exponential and Logarithmic Functions
| Function | Description |
|---|---|
exp(x) | Returns e raised to the power x |
ldexp(x, n) | Returns x * 2^n |
log(x) | Calculates the natural logarithm of x |
log10(x) | Calculates the base 10 logarithm of x |