Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add prefix:<abs>(Real), redefine Real.abs to do calculation directly …
…instead of using .Bridge.
  • Loading branch information
colomon committed Jul 16, 2011
1 parent e707e6e commit fa9c35c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/Numeric.pm
Expand Up @@ -33,7 +33,7 @@ proto prefix:<->(|$) { * }
multi prefix:<->(\$a) { -$a.Numeric }

proto prefix:<abs>(|$) { * }
multi prefix:<abs>(\$a) { abs $a.Numeric }
multi prefix:<abs>(\$a) { abs $a.Numeric }

proto sub log(|$) {*}
multi sub log(Numeric $x) { $x.log }
Expand Down
6 changes: 5 additions & 1 deletion src/core/Real.pm
Expand Up @@ -2,7 +2,7 @@ class Complex { ... }

# XxX role Real does Numeric { ... }
my class Real {
method abs() { self.Bridge.abs }
method abs() { self < 0 ?? -self !! self }
method sqrt() { self.Bridge.sqrt }
method sin() { self.Bridge.sin }
method cos() { self.Bridge.cos }
Expand Down Expand Up @@ -60,3 +60,7 @@ multi sub infix:<mod>(Real $a, Real $b) {
$a - ($a div $b) * $b;
}

multi prefix:<abs>(Real \$a) {
$a < 0 ?? -$a !! $a;
}

0 comments on commit fa9c35c

Please sign in to comment.