math Library

5.1 functions removed or deprecated later: math.pow (use ^), math.ldexp/frexp, math.cosh/sinh/tanh, math.log10 (use math.log(x, 10)).

print(math.pi, math.huge, -math.huge, math.maxinteger, math.mininteger)
print(math.abs(-3), math.ceil(2.1), math.floor(2.9), math.fmod(-7, 3), math.modf(-2.5))
print(math.sqrt(2), math.exp(1), math.log(100, 10), math.log(math.exp(2)))
print(math.sin(0), math.cos(0), math.tan(math.pi / 4), math.asin(1), math.acos(1), math.atan(1, 1))
print(math.deg(math.pi), math.rad(180))
print(math.max(1, 5, 3), math.min(1, 5, 3))
print(math.tointeger(5.0), math.type(5), math.type(5.0), math.ult(1, -1))
math.randomseed(42)                      -- 5.4 uses xoshiro256**; seeded randomly at startup
print(math.random(), math.random(6), math.random(10, 20))
local function round(x) return x >= 0 and math.floor(x + 0.5) or math.ceil(x - 0.5) end
local function clamp(x, lo, hi) return math.max(lo, math.min(hi, x)) end
local function lerp(a, b, t) return a + (b - a) * t end