Skip to content

Commit

Permalink
A better factoring of Rat.perl.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Mar 6, 2013
1 parent fec64aa commit 90bd93d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/Rat.pm
Expand Up @@ -4,12 +4,10 @@ my class Rat is Cool does Rational[Int, Int] {
method FatRat(Rat:D: Real $?) { FatRat.new($.numerator, $.denominator); }
multi method perl(Rat:D:) {
my $d = $.denominator;
if ($d != 1) {
$d div= 5 while $d %% 5;
$d div= 2 while $d %% 2;
return self.Str if $d == 1;
}
$.numerator ~ ( ($d == 1) ?? '.0' !! '/' ~ $.denominator);
return $.numerator ~ '.0' if $d == 1;
$d div= 5 while $d %% 5;
$d div= 2 while $d %% 2;
($d == 1) ?? self.Str !! $.numerator ~ '/' ~ $.denominator;
}
}

Expand Down

0 comments on commit 90bd93d

Please sign in to comment.