Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
coercion methods to FatRat
  • Loading branch information
moritz committed Feb 13, 2012
1 parent 6b1cbaa commit 5d20cb5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/core/Int.pm
Expand Up @@ -30,6 +30,9 @@ my class Int {
method Rat(Int:D: $?) {
Rat.new(self, 1);
}
method FatRat(Int:D: $?) {
FatRat.new(self, 1);
}

method abs(Int:D:) {
nqp::abs_I(self, Int)
Expand Down
8 changes: 5 additions & 3 deletions src/core/Num.pm
Expand Up @@ -30,7 +30,7 @@ my class Num {
}
}

method Rat(Num:D: Real $epsilon = 1.0e-6) {
method Rat(Num:D: Real $epsilon = 1.0e-6, :$fat) {
my sub modf($num) { my $q = $num.Int; $num - $q, $q; }

(self == $Inf || self == -$Inf) && fail("Cannot coerce Inf to a Rat");
Expand All @@ -57,8 +57,10 @@ my class Num {
# smaller denominator but it is not (necessarily) the Rational
# with the smallest denominator that has less than $epsilon error.
# However, to find that Rational would take more processing.

($signum * $b) / $d;
$fat ?? FatRat.new($signum * $b, $d) !! ($signum * $b) / $d;
}
method FatRat(Num:D: Real $epsilon = 1.0e-6) {
self.Rat($epsilon, :fat);
}

multi method atan2(Num:D: Num:D $x = 1e0) {
Expand Down
1 change: 0 additions & 1 deletion src/core/Rat.pm
Expand Up @@ -55,7 +55,6 @@ my role Rational is Real {
}
}

my class FatRat { ... }
# XXX: should also be Cool
my class Rat does Rational {
method Rat (Rat:D: Real $?) { self }
Expand Down
1 change: 1 addition & 0 deletions src/core/stubs.pm
Expand Up @@ -10,6 +10,7 @@ my class KeyHash is Iterable does Associative { }
my class Seq is List does Positional { }
my class Exception { ... }
my class X::AdHoc { ... }
my class FatRat { ... }

sub DYNAMIC(\$name) is rw {
my Mu $x := pir::find_dynamic_lex__Ps(nqp::unbox_s($name));
Expand Down

0 comments on commit 5d20cb5

Please sign in to comment.