Math operators
Try it yourself →Basic arithmetic, integer division, remainder, and exponentiation.
Syntax
+ - * / %/% %% ^
Description
/ gives a decimal. Integer division is done with %/%, remainder with %%, exponentiation with ^.
Example
cat(7 + 3, "\n", sep="") cat(7 / 2, "\n", sep="") cat(7 %/% 2, "\n", sep="") cat(7 %% 2, "\n", sep="") cat(2 ^ 10, "\n", sep="")
Expected output
10 3.5 3 1 1024
When to use?
Calculations, even/odd checks (x %% 2).
Common mistakes
- ⚠️ Integer division is %/%, remainder is %% (not a single %).