Arithmetic operator
Lua’s arithmetic operators are shown in the following table:
| Arithmetic operator | Description |
|---|---|
| + | addition |
| - | subtraction |
| * | multiplication |
| / | division |
| ^ | exponential |
| % | modular |
Sample code:
Print (1 + 2) - > Print 3
Print (5/10) - > Print 0.5. This is Lua different from C.
Print (5.0/10) - > Print 0.5. The result of floating-point division is floating-point number.
Print (2 ^ 10) - > Print 1024. Find the 10 th power of 2
Localnum = 1357
Print (num%) 2 - > Print 1
Print ((num%) 2) == 1) --> print true. Judging whether num is odd
Print ((num% 5) == 0) --> print false. Judging whether num can be 5 integers
Relational operator
