Skip to content

Commit

Permalink
move Num.ACCEPTS to the setting, and make Complex ~~ Num a bit smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Sep 30, 2009
1 parent e25aaba commit 1cd0864
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
17 changes: 0 additions & 17 deletions src/classes/Num.pir
Expand Up @@ -50,23 +50,6 @@ Num - Perl 6 numbers
.return ($I0)
.end


=item ACCEPTS()

=cut

.sub 'ACCEPTS' :method
.param num topic
$S0 = self
if $S0 == 'NaN' goto test_nan
.tailcall 'infix:=='(topic, self)
test_nan:
$S0 = topic
$I0 = iseq $S0, 'NaN'
.tailcall 'prefix:?'($I0)
.end


=item succ and pred

Increment and Decrement Methods
Expand Down
16 changes: 16 additions & 0 deletions src/setting/Num.pm
@@ -1,4 +1,18 @@
class Num is also {
multi method ACCEPTS($other) {
if self eq 'NaN' {
$other eq 'NaN';
} else {
$other == self;
}
}
multi method ACCEPTS(Complex $other) {
if self eq 'NaN' {
$other.re eq 'NaN' || $other.im eq 'NaN';
} else {
$other.im == 0 && $other.re == self;
}
}
multi method Complex() {
Complex.new(self, 0);
}
Expand Down Expand Up @@ -316,3 +330,5 @@ class Num is also {
Complex.new(self * $angle.cos("radians"), self * $angle.sin("radians"));
}
}

# vim: ft=perl6

0 comments on commit 1cd0864

Please sign in to comment.