Skip to content

Commit

Permalink
save a call in Rat.new
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Nov 12, 2011
1 parent 3014678 commit db5d137
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/core/Rat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@ my class Rat is Real {
has Int $.denominator;

method new(Int \$nu = 0, Int \$de = 1) {
my $new := nqp::create(self);
my $gcd = $nu gcd $de;
my Rat $new := nqp::create(self);
my Int $gcd := $nu gcd $de;
my $numerator = $nu div $gcd;
my $denominator = $de div $gcd;
if $denominator < 0 {
$numerator = -$numerator;
$denominator = -$denominator;
}
$new.BUILD($numerator, $denominator);
nqp::bindattr($new, self.WHAT, '$!numerator', nqp::p6decont($numerator));
nqp::bindattr($new, self.WHAT, '$!denominator', nqp::p6decont($denominator));
$new;
}
submethod BUILD(Int \$nu, Int \$de) {
$!numerator = $nu;
$!denominator = $de;
}

method nude() { $!numerator, $!denominator }
method Num() {
Expand Down

0 comments on commit db5d137

Please sign in to comment.