Skip to content

Commit

Permalink
Move Rat.Str to new standard, add Rat.nude.
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
LastOfTheCarelessMen authored and moritz committed Sep 1, 2009
1 parent 0d6c42b commit ba10463
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/setting/Rat.pm
Expand Up @@ -2,12 +2,10 @@ class Rat {
has $.numerator;
has $.denominator;

my sub gcd(Int $a is copy, Int $b is copy)
{
my sub gcd(Int $a is copy, Int $b is copy) {
$a = -$a if ($a < 0);
$b = -$b if ($b < 0);
while $a > 0 && $b > 0
{
while $a > 0 && $b > 0 {
($a, $b) = ($b, $a) if ($b > $a);
$a %= $b;
}
Expand All @@ -24,12 +22,14 @@ class Rat {
$denominator = $denominator div $gcd;
self.bless(*, :$numerator, :$denominator);
}

multi method perl() { "$!numerator/$!denominator"; }

multi method Str() { $.Num.Str }
multi method perl() { "$!numerator/$!denominator"; }

multi method Num() { $!numerator.Num / $!denominator.Num }

multi method Str() { $.Num.Str; }

multi method nude() { $.numerator, $.denominator; }
}

multi sub infix:<+>(Rat $a, Rat $b) {
Expand Down

0 comments on commit ba10463

Please sign in to comment.