Extends the Lua 5.2 math library, adding more capabilities and functions.
local math = require("__flib__.math")
round(num[, divisor=1]) | Round a number to the nearest integer. |
round_to(num, num_decimals) | Round a number to the nearest N decimal places. |
ceil_to(num, num_decimals) | Ceil a number to N decimal places. |
floor_to(num, num_decimals) | Floor a number to N decimal places. |
mean(set) | Calculate the mean (average) of a set of numbers. |
clamp(x, min, max) | Clamp a number between minimum and maximum values. |
lerp(num1, num2, amount) | Linearly interpolate between num1 and num2 by amount . |
deg_to_rad | Multiply by degrees to convert to radians. |
rad_to_deg | Multiply by radians to convert to degrees. |
max_double | Max double |
min_double | Min double |
max_int8 | 127 |
min_int8 | -128 |
max_uint8 | 255 |
max_int16 | 32,767 |
min_int16 | -32,768 |
max_uint16 | 65,535 |
max_int | 2,147,483,647 |
min_int | -2,147,483,648 |
max_uint | 4,294,967,295 |
max_int53 | 9,007,199,254,740,991 |
min_int53 | -9,007,199,254,740,992 |
Round a number to the nearest integer.
This function is measurably faster than math.round_to and should be used in place of it where applicable.
From lua-users.org.
Parameters:num
will be rounded to the nearest multiple of divisor
.
(default: 1)
Round a number to the nearest N decimal places.
Use math.round if no decimals are needed. From lua-users.org.
Parameters: Returns:Ceil a number to N decimal places.
Use math.ceil
directly if no decimals are needed.
Floor a number to N decimal places.
Use math.floor
directly if no decimals are needed.
Calculate the mean (average) of a set of numbers.
Parameters:
Clamp a number between minimum and maximum values.
Parameters: Returns:
Linearly interpolate between num1
and num2
by amount
.
The parameter amount
is clamped between 0
and 1
.
When amount = 0
returns num1
.
When amount = 1
returns num2
.
When amount = 0.5
returns the midpoint of num1
and num2
.