September 2017
Beginner
402 pages
9h 52m
English
This pair of operators, div and mod, are the integer analogs of the / and % operators. The div and mod operators treat their operands as Int values, and the result is also an integer.
Let's examine a few examples:
say 100 div 3; # 33say 10 div 3; # 3say 10 div 5; # 2
The mod operator returns the remainder of the integer division, as you can see here:
say 10 mod 3; # 1
The non-integer operands must be explicitly converted before passing them to the div and mod operators. Otherwise, a compile-time error occurs, as shown here:
$ perl6 -e'say 10 div 3.3'Cannot resolve caller infix:<div>(Int, Rat); none of these signatures match: (Int:D a, Int:D b) (int $a, int $b --> int) in block <unit> at -e line 1
The ...
Read now
Unlock full access