Lua language has a delicate treatment for mathematical operations in order to simplify your life.
Arithmetic operators
note difference type vs math.type
Exponentiation and useful modulo
Basics maths functions
Precedence
| No | Description |
|---|---|
| 1 | ^ |
| 2 | unary operators (-, ~, #, not) |
| 3 | /, //, *, % |
| 4 | +, - |
| 5 | .. (concatenation) |
| 6 | <<, >> (bitwise shifts) |
| 7 | & (bitwise AND) |
| 8 | ~ (bitwise exclusive OR) |
| 9 | ▏(bitwise OR) |
| 10 | <, >, <=, >=, ==, ~= |
| 11 | and |
| 12 | or |
References
- Roberto Ierusalimschy, Programming in Lua, Fourth Edition.
- lua.org
Previous post