Math
This page documents the changes & additions to the math
library in Pluto, which is built on top of Lua 5.4's.
math.isnan
Checks if a number is NaN.
Parameters
- The number to check.
pluto
local x = 0 / 0print(x ~= x) -- Lua way: Prove the variable is NaN because it is not equal to itself. Works, but unintuitive.print(math.isnan(x))
math.round
Rounds a number to the nearest integer.
Parameters
- The number to round.
pluto
print(math.round(2.4)) --> 2print(math.round(2.5)) --> 3
math.trunc
Truncates the fractional part of a number, returning the integer portion toward zero.
Parameters
- The number to truncate.
pluto
print(math.trunc(10.5)) --> 10print(math.trunc(-10.5)) --> -10
math.cbrt
Returns the cube root of a number.
Parameters
- The number to take the cube root of.
pluto
print(math.cbrt(27)) --> 3print(math.cbrt(-27)) --> -3
math.hypot
Returns the square root of the sum of squares of its arguments.
Parameters
- Two numbers representing orthogonal components.
pluto
print(math.hypot(3, 4)) --> 5print(math.hypot(1e155, 1e155)) --> 1.41421e155
math.atan2
An alias for the math.atan
function.
math.inf
An alias for the math.huge
constant.