Math operators
Try it yourself →Basic arithmetic, integer division, remainder, and exponentiation.
Syntax
+ - * / intdiv() % **
Description
7/2 gives a decimal (3.5). Integer division is done with a.intdiv(b). % gives the remainder, and ** gives the exponent.
Example
println 7 + 3 println 7 / 2 println 7.intdiv(2) println 7 % 2 println 2 ** 10
Expected output
10 3.5 3 1 1024
When to use?
Calculations, even/odd checks (x % 2).
Common mistakes
- ⚠️ 7/2 gives a decimal; use intdiv() for an integer result.