Raku Books / Perl 6 at a Glance / Operators / Numerical operators

div, mod

div is the integer division operator. If the floating point is truncated, the result is rounded to the preceding lower integer.

say 10 div 3;  # 3
say -10 div 3; # -4

mod is another form of the modulo:

say 10 % 3;   # 1
say 10 mod 3; # 1

CodeBlockPlaceholder3raku say 10 % “3”; # 1 CodeBlockPlaceholder4

With a mod operator, an error occurs:

say 10 mod "3";

Calling 'infix:<mod>' will never work with argument types (Int, Str) 
Expected any of: :(Real $a, Real $b)

CodeBlockPlaceholder6raku say 10 mod +“3”; # 1 CodeBlockPlaceholder7

or calling the .Int method:

say 10 mod "3".Int; # 1

CodeBlockPlaceholder9raku say 10 %% 3; # False say 12 %% 3; # True CodeBlockPlaceholder10

Course navigation

+, -, *, /   |   +&, +|, +^