Skip to content

Commit

Permalink
Add implementation example for polymod
Browse files Browse the repository at this point in the history
  • Loading branch information
zoffixznet committed May 18, 2016
1 parent d768666 commit be5139e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions doc/Type/Int.pod
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,23 @@ divisors. All divisors must be Ints, unless the method is called on a non-Int nu
say ⅔.polymod(⅓); # (0 2)
say 5.Rat.polymod(.3, .2); # (0.2 0 80)
To illustrate how the Int, non-lazy version of polymod works, consider
this code that implements it:
my $seconds = 2 * 60*60*24 # days
+ 3 * 60*60 # hours
+ 4 * 60 # minutes
+ 5; # seconds
my @pieces;
for 60, 60, 24 -> $divisor {
@pieces.push: $seconds mod $divisor;
$seconds div= $divisor
}
@pieces.push: $seconds;
say @pieces; # [5 4 3 2]
For a more detailed discussion, see
L<this blog post|http://perl6.party/post/Perl6-.polymod-break-up-a-number-into-denominations>
Expand Down

0 comments on commit be5139e

Please sign in to comment.