Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move .sin method to Numeric and Real, cleaning up the Num and Complex…
… versions a tad in the process. Also clean up the Real.unpolar code, and delete the now unneeded Num.unpolar.
  • Loading branch information
colomon committed May 7, 2010
1 parent badc61d commit def9f9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/core/Complex.pm
Expand Up @@ -59,8 +59,8 @@ class Complex does Numeric is Cool {
}
}
multi method sin($base = Radians) {
$.re.sin($base) * $.im.cosh($base) + ($.re.cos($base) * $.im.sinh($base))i;
method sin(Complex $x: $base = Radians) {
$x.re.sin($base) * $x.im.cosh($base) + ($x.re.cos($base) * $x.im.sinh($base))i;
}

multi method asin($base = Radians) {
Expand Down
8 changes: 2 additions & 6 deletions src/core/Num.pm
Expand Up @@ -91,8 +91,8 @@ augment class Num does Real {
pir::sqrt__Nn(self);
}

multi method sin($base = Radians) {
pir::sin__Nn(self.to-radians($base));
method sin(Num $x: $base = Radians) {
pir::sin__Nn($x.to-radians($base));
}

multi method asin($base = Radians) {
Expand Down Expand Up @@ -190,10 +190,6 @@ augment class Num does Real {
multi method atan2(Num $x = 1, $base = Radians) {
pir::atan__NNn(self, $x).from-radians($base);
}

our ::Complex multi method unpolar($angle) {
Complex.new(self * $angle.cos("radians"), self * $angle.sin("radians"));
}
}

# vim: ft=perl6
5 changes: 5 additions & 0 deletions src/core/Numeric.pm
Expand Up @@ -38,4 +38,9 @@ role Numeric {
method from-radians(Numeric $x: $base) {
$x / pir::get_global__Ps('@trig-base-conversions')[$base];
}

method sin(Numeric $x: $base = Radians) {
note "$.WHAT() needs a version of .sin";
fail "$.WHAT() needs a version of .sin";
}
}
8 changes: 6 additions & 2 deletions src/core/Real.pm
Expand Up @@ -41,13 +41,17 @@ role Real does Numeric {

# CHEAT: the .Bridges in unpolar should go away in the long run
method unpolar(Real $mag: Real $angle) {
Complex.new($mag.Bridge * $angle.Bridge.cos("radians"),
$mag.Bridge * $angle.Bridge.sin("radians"));
Complex.new($mag * $angle.Bridge.cos(Radians),
$mag * $angle.sin(Radians));
}

method cis(Real $angle:) {
1.unpolar($angle);
}

method sin(Real $x: $base = Radians) {
$x.Bridge.sin($base);
}
}

multi sub infix:«<=>»(Real $a, Real $b) {
Expand Down

0 comments on commit def9f9c

Please sign in to comment.