Browse files

don't infiniloop when trying to .perl a Rat with 0 denominator

  • Loading branch information...
1 parent 5faaf15 commit 0506d2a7bb88982722b7978258d8ae8dec77aee3 @timo timo committed Jun 19, 2013
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/core/Rat.pm
View
6 src/core/Rat.pm
@@ -5,8 +5,10 @@ my class Rat is Cool does Rational[Int, Int] {
multi method perl(Rat:D:) {
my $d = $.denominator;
return $.numerator ~ '.0' if $d == 1;
- $d div= 5 while $d %% 5;
- $d div= 2 while $d %% 2;
+ unless $d == 0 {
+ $d div= 5 while $d %% 5;
+ $d div= 2 while $d %% 2;
+ }
($d == 1) ?? self.Str !! '<' ~ $.numerator ~ '/' ~ $.denominator ~ '>';
}
}

0 comments on commit 0506d2a

Please sign in to comment.