math
Numbers beyond + - * /: square roots, powers, rounding, trigonometry.
import math
Example
import math
say(math.sqrt(16), math.pow(2, 10))
say(math.round(math.pi, 3))
say(math.clamp(15, 0, 10))
say(math.max([3, 9, 4]))
Functions
sqrt(x)
returns numberThe square root: sqrt(9) is 3.
pow(x, y)
returns numberx to the power y: pow(2, 10) is 1024.
floor(x)
returns numberThe whole number at or below x: floor(2.7) is 2.
ceil(x)
returns numberThe whole number at or above x: ceil(2.1) is 3.
abs(x)
returns numberx without its minus sign.
round(x, digits?)
returns numberRounded to digits after the dot (default 0). Halves round away from zero.
log(x, base?)
returns numberThe logarithm of x (natural log, or in the given base).
sin(x)
returns numberThe sine of x (x in radians).
cos(x)
returns numberThe cosine of x (x in radians).
tan(x)
returns numberThe tangent of x (x in radians).
min(a, b, ...) or min(list)
returns numberThe smallest number.
max(a, b, ...) or max(list)
returns numberThe biggest number.
clamp(x, low, high)
returns numberx, kept between low and high: clamp(15, 0, 10) is 10.
Values
| Name | Value | What it is |
|---|---|---|
math.pi | 3.141592653589793 | The circle number, 3.14159... |
math.e | 2.718281828459045 | Euler's number, 2.71828... |