Skip to content
AEOWUN
Docs Menu

Math

Look up math calls and properties.

math.abs(x)

Return the distance of a number from zero.

Arguments

x: numbers.

Returns

A non-negative number.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.abs(-5))

math.min(a, b)

Return the smaller number.

Arguments

a, b: numbers.

Returns

The smaller number.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.min(2, 5))

math.max(a, b)

Return the larger number.

Arguments

a, b: numbers.

Returns

The larger number.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.max(2, 5))

math.floor(x)

Round down to a whole number.

Arguments

x: numbers.

Returns

The largest integer no greater than x.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.floor(2.8))

math.ceil(x)

Round up to a whole number.

Arguments

x: numbers.

Returns

The smallest integer no less than x.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.ceil(2.2))

math.round(x)

Round to the nearest whole number.

Arguments

x: numbers.

Returns

The rounded number. Halfway values round away from zero.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.round(2.5))

math.sqrt(x)

Return the square root.

Arguments

x: numbers.

Returns

The square root; a negative input produces NaN.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.sqrt(9))

math.pow(base, exponent)

Raise a number to a power.

Arguments

base, exponent: numbers.

Returns

The numeric result. Some inputs produce NaN or infinity.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.pow(2, 3))

math.sin(radians)

Return the sine of an angle.

Arguments

radians: numbers.

Returns

A number.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.sin(math.deg_to_rad(90)))

math.cos(radians)

Return the cosine of an angle.

Arguments

radians: numbers.

Returns

A number.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.cos(0))

math.tan(radians)

Return the tangent of an angle.

Arguments

radians: numbers.

Returns

A number.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.tan(0))

math.deg_to_rad(degrees)

Convert degrees to radians.

Arguments

degrees: numbers.

Returns

The angle in radians.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.deg_to_rad(180))

math.rad_to_deg(radians)

Convert radians to degrees.

Arguments

radians: numbers.

Returns

The angle in degrees.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.rad_to_deg(3.141592653589793))

math.clamp(value, min, max)

Keep a number within a range.

Arguments

value, min, max: numbers.

Returns

A number between min and max, including both ends.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error. A minimum greater than the maximum reports an error.

debug.log(math.clamp(120, 0, 100))

math.lerp(a, b, t)

Find a value along the range from a to b.

Arguments

a, b, t: numbers.

Returns

a + (b - a) * t. The value of t is not clamped.

Works with

Numbers.

Missing values and errors

Wrong argument counts or types report an error.

debug.log(math.lerp(0, 10, 0.5))

math.random() or math.random(min, max)

Choose a random number.

Arguments

No arguments, or two numeric bounds. Range bounds are converted to integers.

Returns

With no arguments, a number from 0 up to but not including 1. With bounds, a whole number including both ends.

Works with

Numbers.

Missing values and errors

One argument, more than two arguments, or a minimum greater than the maximum reports an error.

debug.log(math.random())
debug.log(math.random(1, 6))

[BETA] marks features newer than the current public release. Current release: 0.8.0.