Luawe the Wayfarer Engine's scripting language All pages

math

Numbers. There is no math.random: random numbers are the random library's.

math.pi

3.14159..., half a turn in radians.

math.huge

A number bigger than any other (infinity).

math.abs

math.abs(x)

x without its sign.

math.floor

math.floor(x)

x rounded down to a whole number.

math.ceil

math.ceil(x)

x rounded up to a whole number.

math.round

math.round(x, places?)

x rounded to the nearest whole number, or to that many decimal places.

math.min

math.min(x, ...)

The smallest of its numbers.

math.max

math.max(x, ...)

The biggest of its numbers.

math.clamp

math.clamp(x, least, most)

x kept between least and most.

math.sign

math.sign(x)

-1, 0 or 1: which way x points.

math.lerp

math.lerp(a, b, t)

The number t of the way from a to b (t from 0 to 1).

math.map

math.map(x, fromLow, fromHigh, toLow, toHigh)

x moved from one range to another: math.map(5, 0, 10, 100, 200) is 150.

math.sqrt

math.sqrt(x)

The square root of x.

math.pow

math.pow(x, y)

x to the power y (the same as x ^ y).

math.exp

math.exp(x)

e to the power x.

math.log

math.log(x, base?)

The logarithm of x: natural, or in the base given.

math.sin

math.sin(angle)

The sine of an angle in radians.

math.cos

math.cos(angle)

The cosine of an angle in radians.

math.tan

math.tan(angle)

The tangent of an angle in radians.

math.asin

math.asin(x)

The angle (radians) whose sine is x.

math.acos

math.acos(x)

The angle (radians) whose cosine is x.

math.atan

math.atan(y, x?)

The angle (radians) of the point x, y: the direction from one place to another is math.atan(dy, dx).

math.deg

math.deg(radians)

Radians as degrees.

math.rad

math.rad(degrees)

Degrees as radians.

math.fmod

math.fmod(x, y)

What is left of x after dividing by y, with the sign of x. (x % y has the sign of y.)

math.modf

math.modf(x)

x in two parts: its whole part and what comes after the point.