Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Straighten out type issues with Real.exp. In the process, add Real * …
…Real, Complex ** Real, and Real ** Complex.
  • Loading branch information
colomon committed Apr 28, 2010
1 parent 72f914f commit 3966c62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/core/Complex.pm
Expand Up @@ -286,11 +286,11 @@ multi sub infix:<*>(Complex $a, Complex $b) {
Complex.new($a.re * $b.re - $a.im * $b.im, $a.im * $b.re + $a.re * $b.im);
}

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 * $b.re, $a * $b.im);
}

Expand Down Expand Up @@ -332,6 +332,14 @@ multi sub infix:<**>($a, Complex $b) {
($a.log * $b).exp;
}

multi sub infix:<**>(Complex $a, Real $b) {
($a.log * $b).exp;
}

multi sub infix:<**>(Real $a, Complex $b) {
($a.log * $b).exp;
}

multi sub log(Complex $x) {
$x.log()
}
Expand Down
14 changes: 11 additions & 3 deletions src/core/Real.pm
Expand Up @@ -10,12 +10,12 @@ role Real does Numeric {
}

# Hmmm... should the second argument be Numeric for the next two?
method exp(Real $exponent: Real $base = e) {
method exp(Real $exponent: Numeric $base = e) {
$base ** $exponent;
}

method log(Real $x: Real $base = e) {
$x.Bridge.log($base.Bridge);
method log(Real $x: Numeric $base = e) {
$x.Bridge.log($base);
}

method sign(Real $x:) {
Expand Down Expand Up @@ -98,6 +98,14 @@ multi sub infix:<->(Num $a, Num $b) {
pir::sub__NNN($a, $b)
}

multi sub infix:<*>(Real $a, Real $b) {
$a.Bridge * $b.Bridge;
}

multi sub infix:<*>(Num $a, Num $b) {
pir::mul__NNN($a, $b)
}

multi sub infix:</>(Real $a, Real $b) {
$a.Bridge / $b.Bridge;
}
Expand Down

0 comments on commit 3966c62

Please sign in to comment.