Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
polymod yields 1 more result than args unless inf
  • Loading branch information
TimToady committed Feb 14, 2015
1 parent 874caf6 commit 0e61279
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/Int.pm
Expand Up @@ -62,10 +62,11 @@ my class Int does Real { # declared in BOOTSTRAP
# If do-not-want, user should cast invocant to proper domain.
method polymod(Int:D: *@mods) {
my $more = self;
my $inf = @mods.elems == Inf;
fail X::OutOfRange.new(what => 'invocant to polymod', got => $more, range => "0..*") if $more < 0;
gather {
for @mods -> $mod {
last unless $more;
last if $inf and not $more;
fail X::Numeric::DivideByZero.new(using => 'polymod') unless $mod;
take $more mod $mod;
$more div= $mod;
Expand Down
3 changes: 2 additions & 1 deletion src/core/Real.pm
Expand Up @@ -66,10 +66,11 @@ my role Real does Numeric {

method polymod(Real:D: *@mods) {
my $more = self;
my $inf = @mods.elems == Inf;
fail X::OutOfRange.new(what => 'invocant to polymod', got => $more, range => "0..*") if $more < 0;
gather {
for @mods -> $mod {
last unless $more;
last if $inf and not $more;
fail X::Numeric::DivideByZero.new(using => 'polymod') unless $mod;
take my $rem = $more % $mod;
$more -= $rem;
Expand Down

0 comments on commit 0e61279

Please sign in to comment.