Math Functions
The Math category provides mathematical operations that mirror the functionality of Math nodes.
Available Functions
Basic Operations
Math.add(a, b)- Adds two numbersMath.sub(a, b)- Subtracts b from aMath.mul(a, b)- Multiplies two numbersMath.div(a, b)- Divides a by bMath.mod(a, b)- Returns the remainder of a divided by b
Advanced Operations
Math.abs(value)- Returns the absolute valueMath.sqrt(value)- Returns the square rootMath.pow(base, exponent)- Returns base raised to the power of exponentMath.ceil(value)- Rounds up to the nearest integerMath.floor(value)- Rounds down to the nearest integerMath.round(value)- Rounds to the nearest integerMath.log(value)- Returns the natural logarithmMath.log10(value)- Returns the base-10 logarithmMath.exp(value)- Returns e raised to the power of valueMath.fmod(a, b)- Returns the floating-point remainderMath.hypot(a, b)- Returns the hypotenuse of a right triangle
Min/Max Operations
Math.max(...)- Returns the maximum value from the argumentsMath.min(...)- Returns the minimum value from the arguments
Examples
Basic Arithmetic
local sum = Math.add(10, 20) -- Returns 30
local difference = Math.sub(50, 20) -- Returns 30
local product = Math.mul(5, 6) -- Returns 30
local quotient = Math.div(100, 5) -- Returns 20
local remainder = Math.mod(17, 5) -- Returns 2
Advanced Math
local absValue = Math.abs(-42) -- Returns 42
local squareRoot = Math.sqrt(16) -- Returns 4
local power = Math.pow(2, 8) -- Returns 256
local ceiling = Math.ceil(4.3) -- Returns 5
local floor = Math.floor(4.7) -- Returns 4
local rounded = Math.round(4.5) -- Returns 5
Logarithms and Exponentials
local ln = Math.log(2.71828) -- Returns approximately 1
local log10 = Math.log10(100) -- Returns 2
local exp = Math.exp(1) -- Returns approximately 2.71828
Min/Max
local maximum = Math.max(10, 20, 5, 30) -- Returns 30
local minimum = Math.min(10, 20, 5, 30) -- Returns 5
Return Values
All functions return a number (integer or float depending on the operation).
Related Nodes
- MathAdd Node
- MathSub Node
- MathMul Node
- MathDiv Node
- MathMod Node
- MathAbsInteger Node
- MathAbsFloat Node
- MathSqrt Node
- MathPow Node
- And other Math nodes...