Arithmetic Operators
Lua supports the usual arithmetic operators: the binary +
(addition), -
(subtraction), *
(multiplication), /
(division), %
(modulo), and ^
(exponentiation); and unary -
(negation). If the operands are numbers, or strings that can be converted to numbers (see Coercion), then all operations have the usual meaning. Exponentiation works for any exponent. For instance, x^(-0.5)
computes the inverse of the square root of x
. Modulo is defined as
a % b == a – math.floor(a/b)*b
That is, it is the remainder of a division that rounds the quotient towards minus infinity.