Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Have Rat.perl return decimal numbers if denominator is normalizable t…
…o a power of 10. Fixes RT #117013.
  • Loading branch information
pmichaud committed Mar 3, 2013
1 parent 123dfa3 commit fd27043
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/Rat.pm
Expand Up @@ -3,9 +3,16 @@ my class Rat is Cool does Rational[Int, Int] {
method Rat (Rat:D: Real $?) { self }
method FatRat(Rat:D: Real $?) { FatRat.new($.numerator, $.denominator); }
multi method perl(Rat:D:) {
$.numerator ~ '/' ~ $.denominator
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);
}
}

my class FatRat is Cool does Rational[Int, Int] {
method FatRat(FatRat:D: Real $?) { self }
method Rat (FatRat:D: Real $?) {
Expand Down

0 comments on commit fd27043

Please sign in to comment.