Math & utility · BUILT-IN MODULE

math

Mathematics, trigonometry, combinatorics, and statistics.

Quick start

use math
use math

say math.sqrt 81
say math.factorial 5
say math.clamp 120 0 100
say math.pi

API reference

math.pi

Pi.

Pi.
math.e

Euler number.

Euler number.
math.tau

Tau (2*pi).

Tau (2*pi).
math.inf

Positive infinity.

Positive infinity.
math.sqrt number

Numeric math helper.

Numeric math helper.
math.cbrt number

Numeric math helper.

Numeric math helper.
math.abs number

Numeric math helper.

Numeric math helper.
math.floor number

Numeric math helper.

Numeric math helper.
math.ceil number

Numeric math helper.

Numeric math helper.
math.round number

Numeric math helper.

Numeric math helper.
math.trunc number

Numeric math helper.

Numeric math helper.
math.sin number

Numeric math helper.

Numeric math helper.
math.cos number

Numeric math helper.

Numeric math helper.
math.tan number

Numeric math helper.

Numeric math helper.
math.asin number

Numeric math helper.

Numeric math helper.
math.acos number

Numeric math helper.

Numeric math helper.
math.atan number

Numeric math helper.

Numeric math helper.
math.sinh number

Numeric math helper.

Numeric math helper.
math.cosh number

Numeric math helper.

Numeric math helper.
math.tanh number

Numeric math helper.

Numeric math helper.
math.asinh number

Numeric math helper.

Numeric math helper.
math.acosh number

Numeric math helper.

Numeric math helper.
math.atanh number

Numeric math helper.

Numeric math helper.
math.exp number

Numeric math helper.

Numeric math helper.
math.exp2 number

Numeric math helper.

Numeric math helper.
math.expm1 number

Numeric math helper.

Numeric math helper.
math.log number

Numeric math helper.

Numeric math helper.
math.log10 number

Numeric math helper.

Numeric math helper.
math.log2 number

Numeric math helper.

Numeric math helper.
math.log1p number

Numeric math helper.

Numeric math helper.
math.degrees number

Numeric math helper.

Numeric math helper.
math.radians number

Numeric math helper.

Numeric math helper.
math.gamma number

Numeric math helper.

Numeric math helper.
math.lgamma number

Numeric math helper.

Numeric math helper.
math.erf number

Numeric math helper.

Numeric math helper.
math.erfc number

Numeric math helper.

Numeric math helper.
math.atan2 a b

Two-number math helper.

Two-number math helper.
math.pow a b

Two-number math helper.

Two-number math helper.
math.fmod a b

Two-number math helper.

Two-number math helper.
math.remainder a b

Two-number math helper.

Two-number math helper.
math.copysign a b

Two-number math helper.

Two-number math helper.
math.nextafter a b

Two-number math helper.

Two-number math helper.
math.hypot number number...

Euclidean norm for two or more values.

Euclidean norm for two or more values.
math.min number number...

Minimum of two or more values.

Minimum of two or more values.
math.max number number...

Maximum of two or more values.

Maximum of two or more values.
math.clamp value min max

Clamp a number into a range.

Clamp a number into a range.
math.lerp a b t

Linear interpolation.

Linear interpolation.
math.map_range value in_min in_max out_min out_max

Map a value between ranges.

映射 a value between ranges.
math.sign number

Return -1, 0, or 1.

回傳 -1, 0, or 1.
math.isfinite number

Check whether a number is finite.

檢查是否 a number is finite.
math.isinf number

Check whether a number is infinite.

檢查是否 a number is infinite.
math.isnan number

Check whether a number is NaN.

檢查是否 a number is NaN.
math.gcd int int...

Greatest common divisor.

Greatest common divisor.
math.lcm int int...

Least common multiple.

Least common multiple.
math.factorial int

Factorial for a non-negative Int.

Factorial for a non-negative Int.
math.comb n k

Number of combinations.

Number of combinations.
math.perm n k

Number of permutations.

Number of permutations.
math.sum list

Sum numeric List values.

Sum numeric List values.
math.mean list

Mean of numeric List values.

Mean of numeric List values.
math.median list

Median of numeric List values.

Median of numeric List values.
math.variance list

Population variance helper.

Population variance helper.
math.stddev list

Population standard deviation helper.

Population standard deviation helper.