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 number

The square root: sqrt(9) is 3.

pow(x, y)

returns number

x to the power y: pow(2, 10) is 1024.

floor(x)

returns number

The whole number at or below x: floor(2.7) is 2.

ceil(x)

returns number

The whole number at or above x: ceil(2.1) is 3.

abs(x)

returns number

x without its minus sign.

round(x, digits?)

returns number

Rounded to digits after the dot (default 0). Halves round away from zero.

log(x, base?)

returns number

The logarithm of x (natural log, or in the given base).

sin(x)

returns number

The sine of x (x in radians).

cos(x)

returns number

The cosine of x (x in radians).

tan(x)

returns number

The tangent of x (x in radians).

min(a, b, ...) or min(list)

returns number

The smallest number.

max(a, b, ...) or max(list)

returns number

The biggest number.

clamp(x, low, high)

returns number

x, kept between low and high: clamp(15, 0, 10) is 10.

Values

NameValueWhat it is
math.pi3.141592653589793The circle number, 3.14159...
math.e2.718281828459045Euler's number, 2.71828...