Skip to content
Browse files

Rat updates, add another spectest.

  • Loading branch information...
1 parent c4ca652 commit 25b3ee67f731f73e1ceec5ef58a2ef945a06ea9c @pmichaud pmichaud committed Jul 5, 2011
Showing with 7 additions and 4 deletions.
  1. +6 −3 src/core/Rat.pm
  2. +1 −1 t/spectest.data
View
9 src/core/Rat.pm
@@ -3,8 +3,8 @@ my class Rat is Real {
has $.numerator;
has $.denominator;
- method new(Rat:U: Int \$nu, Int \$de) {
- my $new = self.CREATE;
+ method new(Int \$nu = 0, Int \$de = 1) {
+ my $new := self.CREATE;
my $gcd = $nu gcd $de;
my $numerator = $nu div $gcd;
my $denominator = $de div $gcd;
@@ -22,8 +22,11 @@ my class Rat is Real {
method nude() { $!numerator, $!denominator }
method Num() {
- $!numerator.Num / $!denominator.Num
+ $!denominator == 0
+ ?? ($!numerator < 0 ?? -$Inf !! $Inf)
+ !! $!numerator.Num / $!denominator.Num
}
+ method Int() { self.Num.Int }
method Bridge() { self.Num }
method Rat() { self }
View
2 t/spectest.data
@@ -525,7 +525,7 @@ S32-num/log.t
S32-num/polar.t
# S32-num/power.t
# S32-num/rand.t
-# S32-num/rat.t
+S32-num/rat.t
# S32-num/real-bridge.t
# S32-num/roots.t
# S32-num/rounders.t

0 comments on commit 25b3ee6

Please sign in to comment.
Something went wrong with that request. Please try again.