Math operators
Try it yourself →Four basic operations, integer division, and remainder.
Syntax
+ - * / div(a,b) rem(a,b)
Description
/ always returns a float (7/2=3.5). Integer division is with div(a,b), remainder with rem(a,b).
Example
IO.puts(7 + 3) IO.puts(7 / 2) IO.puts(div(7, 2)) IO.puts(rem(7, 2))
Expected output
10 3.5 3 1
When to use?
Calculations, even/odd checks (rem(x, 2)).
Common mistakes
- ⚠️ / always returns a float; use div(a,b) for integer results.