The math library in Lua
floor and ceil, // and %, and one number type in two flavors.
-- The math library, and Lua's one number type wearing two faces.
print(math.floor(7.8), math.ceil(7.2))
print(math.max(12, 45, 3), math.min(12, 45, 3))
print("Root of 2: " .. string.format("%.4f", math.sqrt(2)))
-- Integers and floats coexist; // divides toward the floor.
print(7 / 2)
print(7 // 2)
print(7 % 3)
print(math.type(7), math.type(7.0))
-- Deterministic rolls come from a seeded generator.
math.randomseed(20)
print("Seeded roll: " .. math.random(1, 6))
How it works
math.floor/ceilround;max/mintake any count.//floor-divides;math.typetells integer from float.math.randomseedmakes rolls reproducible.
Keywords and builtins used here
print
The run, in numbers
- Lines
- 14
- Characters to type
- 468
- Tokens
- 91
- Three-star pace
- 65 tpm
At the three-star pace of 65 tokens a minute, this run takes about 84 seconds.
Step 1 of 2 in The library, step 23 of 27 in Language basics.