Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Be more specific about types for Complex mixed-type math. Change Any,…
… Any versions of the basic math functions to coerce to Numeric (instead of called PIR functions which coerce to Num).
  • Loading branch information
colomon committed Apr 29, 2010
1 parent fe59fa8 commit 9d955f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/core/Complex.pm
Expand Up @@ -255,11 +255,11 @@ multi sub infix:<+>(Complex $a, Complex $b) {
Complex.new($a.re + $b.re, $a.im + $b.im);
}

multi sub infix:<+>(Complex $a, $b) {
multi sub infix:<+>(Complex $a, Real $b) {
Complex.new($a.re + $b, $a.im);
}

multi sub infix:<+>($a, Complex $b) {
multi sub infix:<+>(Real $a, Complex $b) {
# Was $b + $a; but that trips a ng bug, and also means
# that Num + Complex is slower than Complex + Num, which
# seems daft.
Expand All @@ -274,11 +274,11 @@ multi sub infix:<->(Complex $a, Complex $b) {
Complex.new($a.re - $b.re, $a.im - $b.im);
}

multi sub infix:<->(Complex $a, $b) {
multi sub infix:<->(Complex $a, Real $b) {
Complex.new($a.re - $b, $a.im);
}

multi sub infix:<->($a, Complex $b) {
multi sub infix:<->(Real $a, Complex $b) {
Complex.new($a - $b.re, -$b.im);
}

Expand All @@ -300,11 +300,11 @@ multi sub infix:</>(Complex $a, Complex $b) {
($a.im * $b.re - $a.re * $b.im) / $d);
}

multi sub infix:</>(Complex $a, $b) {
multi sub infix:</>(Complex $a, Real $b) {
Complex.new($a.re / $b, $a.im / $b);
}

multi sub infix:</>($a, Complex $b) {
multi sub infix:</>(Real $a, Complex $b) {
Complex.new($a, 0) / $b;
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/operators.pm
Expand Up @@ -34,27 +34,27 @@ our multi sub prefix:<->($a) {
}

our multi sub infix:<+>($a, $b) {
pir::add__NNN($a, $b)
+$a + +$b;
}

our multi sub infix:<->($a, $b) {
pir::sub__NNN($a, $b)
+$a - +$b;
}

our multi sub infix:<*>($a, $b) {
+$a * +$b;
}

our multi sub infix:</>($a, $b) {
pir::div__NNN($a, $b)
+$a / +$b;
}

our multi sub infix:<%>($a, $b) {
pir::mod__NNN($a, $b)
}

our multi sub infix:<**>($a, $b) {
pir::pow__NNN($a, $b)
(+$a) ** +$b; # parenthesis needed because of precendence.
}

our multi sub infix:<&>(*@items) {
Expand Down

0 comments on commit 9d955f2

Please sign in to comment.