Skip to content

Commit

Permalink
Full support for Complex tanh and atanh.
Browse files Browse the repository at this point in the history
  • Loading branch information
colomon committed Oct 3, 2009
1 parent fc29434 commit d5b578b
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 @@ -122,7 +122,7 @@ class Any is also {
self.Num.cosh($base);
}

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

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

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

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

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

multi sub atanh($x, $base = 'radians') {
$x.atanh($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 @@ -88,6 +88,14 @@ class Complex {
(self + sqrt(self * self - 1)).log!from-radians($base);
}

multi method tanh($base = 'radians') {
-((1i * self).tan($base))i;
}

multi method atanh($base = 'radians') {
(((1 + self) / (1 - self)).log / 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 @@ -153,7 +153,7 @@ class Num is also {
$r!from-radians($base)
}

our Num multi method atanh($base = 'radians') is export {
our Num multi method atanh($base = 'radians') {
my $r = Q:PIR {
$N0 = self
$N1 = 1 - $N0
Expand Down Expand Up @@ -316,7 +316,7 @@ class Num is also {
}
}
our Num multi method tanh($base = 'radians') is export {
our Num multi method tanh($base = 'radians') {
my $x = self!to-radians($base);
Q:PIR {
$P0 = find_lex "$x"
Expand Down

0 comments on commit d5b578b

Please sign in to comment.