LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
math

Extra math functions (extends Lua's math library) More...

Detailed Description

These are added to Lua's standard math library, so math.floor(), math.random(), etc. still work like in normal Lua (see the Lua manual).

Functions

number math.range (number num, number min, number max)
 
boolean math.inrange (number num, number min, number max)
 
number math.round (number num, number decimals)
 

Function Documentation

◆ math.inrange()

boolean math.inrange ( number num,
number min,
number max )

Checks if a number is between a minimum and a maximum (both included)

Parameters
numThe number
minThe minimum
maxThe maximum
Returns
true if min <= num <= max
Example:
-- Is the touch inside a button?
if math.inrange(touch.x, 100, 300) and math.inrange(touch.y, 50, 100) then ... end

◆ math.range()

number math.range ( number num,
number min,
number max )

Keeps a number between a minimum and a maximum (also known as "clamp")

Parameters
numThe number
minThe minimum
maxThe maximum
Returns
min if num is smaller than it, max if num is bigger than it, otherwise num
Example:
volume = math.range(volume + 10, 0, 100) -- never goes over 100

◆ math.round()

number math.round ( number num,
number decimals )

Rounds a number to the nearest whole number, or to a number of decimal places

Parameters
numThe number
decimalsHow many decimal places to keep (optional, default: 0)
Returns
The rounded number
Example:
print(math.round(2.5)) -- 3
print(math.round(3.14159, 2)) -- 3.14