Permalink
Browse files

exp, infix ** for Complex

  • Loading branch information...
moritz committed Jul 3, 2011
1 parent f37d574 commit a08f69ea4bcf923c41ef9c8abfaef644ca90dbaa
Showing with 25 additions and 1 deletion.
  1. +2 −0 NOMMAP.markdown
  2. +10 −0 src/core/Complex.pm
  3. +4 −0 src/core/Num.pm
  4. +7 −0 src/core/Numeric.pm
  5. +1 −0 src/core/Real.pm
  6. +1 −1 t/spectest.data
View
@@ -20,6 +20,8 @@ Things that aren't blockers but might be worth knowing about:
(known - multis in nested lexical scopes in general just NYI - jnthn)
* 'has num $.attr' segfaults on access to .attr, because it uses the PMC form
of get_attribute
+* two protos of the same name in the same scope produce an IMCC error
+ "error:imcc:Multiple declarations of lexical '&foo'"
## Lexical Multi-Part names
For my X::Base { ... }, my Foo::Bar { ... } etc. The our-scoped ones work.
View
@@ -72,6 +72,12 @@ my class Complex is Numeric {
my Num ($mag, $angle) = self.polar;
Complex.new($mag.log, $angle);
}
+
+ multi method exp() {
+ my Num $mag = $!re.exp;
+ Complex.new($mag * $!im.cos, $mag * $!im.sin);
+ }
+
}
multi sub prefix:<->(Complex \$a) {
@@ -262,6 +268,10 @@ multi sub infix:</>(Real \$a, Complex \$b) {
Complex.new($a, 0) / $b;
}
+multi sub infix:<**>(Complex \$a, Complex \$b) { $b.exp * $a.log }
+multi sub infix:<**>(Real \$a, Complex \$b) { $b.exp * $a.log }
+multi sub infix:<**>(Complex \$a, Real \$b) { $b.exp * $a.log }
+
proto postfix:<i>(|$) { * }
multi postfix:<i>(Real \$a) { Complex.new(0e0, $a); }
multi postfix:<i>(Complex \$a) { Complex.new(-$a.im, $a.re) }
View
@@ -62,6 +62,10 @@ my class Num {
nqp::p6box_n(nqp::abs_n(nqp::unbox_n(self)));
}
+ method exp() {
+ nqp::p6box_n(pir::exp__Nn(nqp::unbox_n(self)));
+ }
+
proto method log(|$) {*}
multi method log() {
nqp::p6box_n(pir::ln__NN(nqp::unbox_n(self)));
View
@@ -5,6 +5,10 @@ my class Numeric {
multi method ACCEPTS(Numeric:D: $a) { $a == self }
proto method log(|$) {*}
+ proto method exp(|$) {*}
+ multi method exp(Numeric $base) {
+ self.exp * $base.log;
+ }
}
@@ -23,6 +27,9 @@ proto sub log(|$) {*}
multi sub log(Numeric $x) { $x.log }
multi sub log(Numeric $x, Numeric $base) { $x.log($base) }
+proto sub exp(|$) {*}
+multi sub exp(Numeric $x) { $x.exp }
+
proto infix:<+>(|$) { * }
multi infix:<+>(\$a, \$b) { $a.Numeric + $b.Numeric }
View
@@ -20,6 +20,7 @@ my class Real {
}
multi method log() { self.Bridge.log }
multi method log(Real $base) { self.Bridge.log($base.Bridge) }
+ multi method exp() { self.Bridge.exp }
}
proto sub cis(|$) {*}
View
@@ -514,7 +514,7 @@ S32-array/bool.t
# S32-list/uniq.t
# S32-num/abs.t
# S32-num/base.t
-# S32-num/complex.t
+S32-num/complex.t
# S32-num/cool-num.t
# S32-num/exp.t
# S32-num/gcd.t

0 comments on commit a08f69e

Please sign in to comment.