Skip to Content
Perl 6 Deep Dive
book

Perl 6 Deep Dive

by Andrew Shitov
September 2017
Beginner
402 pages
9h 52m
English
Packt Publishing
Content preview from Perl 6 Deep Dive

Modulo operator

The % is the modulo operator. It returns the remainder of the division of its operands, as shown here:

say 100 % 3; # 1say 10 % 3;  # 1say 5 % 3;   # 2

The result of the modulo operation $a % $b is equivalent to the following wordy expression:

$a - $b * floor($a / $b);

Here, floor is the function that rounds the value down. Take one of the preceding examples—10 % 3. The result of it means that 3 can be subtracted from 10 a few times until 1 remains, which is less than 3 and thus cannot be decreased by it.

Traditionally, the modulo operator is used with integer operands, but it still works fine with rational and floating-point numbers. The values of these types can be accepted by the % operator without type casts. Let's examine ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe
Learning Perl 6

Learning Perl 6

brian d foy
Think Perl 6

Think Perl 6

Laurent Rosenfeld, Allen B. Downey
Pro Perl

Pro Perl

Peter Wainwright

Publisher Resources

ISBN: 9781787282049Supplemental Content