Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Full support for Complex tan and atan.
  • Loading branch information
colomon committed Oct 2, 2009
1 parent a7d2a98 commit 1354976
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/setting/Any-num.pm
Expand Up @@ -97,7 +97,7 @@ class Any is also {
self.Num.cos($base);
}

our Num multi method tan($base = 'radians') is export {
our Num multi method tan($base = 'radians') {
self.Num.tan($base);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ class Any is also {
self.Num.acos($base);
}

our Num multi method atan($base = 'radians') is export {
our Num multi method atan($base = 'radians') {
self.Num.atan($base);
}

Expand Down Expand Up @@ -212,6 +212,14 @@ multi sub acos($x, $base = 'radians') {
$x.acos($base)
}

multi sub tan($x, $base = 'radians') {
$x.tan($base)
}

multi sub atan($x, $base = 'radians') {
$x.atan($base)
}

our Num sub rand (*@args) {
die "too many arguments passed - 0 params expected" if @args;
1.rand
Expand Down
8 changes: 8 additions & 0 deletions src/setting/Complex.pm
Expand Up @@ -40,6 +40,14 @@ class Complex {
(pi / 2)!from-radians($base) - self.asin($base);
}

multi method tan($base = 'radians') {
self.sin($base) / self.cos($base);
}

multi method atan($base = 'radians') {
((log(1 - (self)i) - log(1 + (self)i))i / 2)!from-radians($base);
}

multi method log() {
Q:PIR {
$P0 = get_root_namespace ['parrot'; 'Complex' ]
Expand Down
4 changes: 2 additions & 2 deletions src/setting/Num.pm
Expand Up @@ -133,7 +133,7 @@ class Num is also {
$r!from-radians($base)
}

our Num multi method atan($base = 'radians') is export {
our Num multi method atan($base = 'radians') {
my $r = Q:PIR {
$N0 = self
$N1 = atan $N0
Expand Down Expand Up @@ -306,7 +306,7 @@ class Num is also {
self;
}

our Num multi method tan($base = 'radians') is export {
our Num multi method tan($base = 'radians') {
my $x = self!to-radians($base);
Q:PIR {
$P0 = find_lex "$x"
Expand Down

0 comments on commit 1354976

Please sign in to comment.