Operators

Arithmetic operators

Full

The numeric infixes — + - / % * div mod — and the types they return.

The arithmetic operators work across the whole numeric tower. Division of integers yields an exact Rat (see Rational literals), not a truncated integer.

The basic set #

say 7 + 3;
say 7 - 3;
say 7 * 3;
say 7 / 2;
say 7 ** 2;
Output
10
4
21
3.5
49

Modulus and integer division #

% is modulus, ** is exponentiation, and div/mod are the integer-only counterparts of / and %.

say 7 % 3;
say 7 div 2;
say 7 mod 3;
Output
1
3
1

gcd and lcm #

Greatest common divisor and least common multiple are built-in infix operators.

say 12 gcd 18;
say 4 lcm 6;
Output
6
12

Notes #