Skip to content

Commit

Permalink
Make Complex sin and asin work correctly.
Browse files Browse the repository at this point in the history
This involved taking "is export" off Num.sin, adding Complex.asin, and implementing Any functions which forward the sub version of sin and asin to method versions.
  • Loading branch information
colomon committed Oct 2, 2009
1 parent 6c4babd commit f52e459
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/setting/Any-num.pm
Expand Up @@ -195,7 +195,14 @@ multi sub abs($x) { (+$x).abs() }
multi sub exp($x) { $x.Num.exp() }
multi sub log($x) { $x.Num.log() }
multi sub log10($x) { $x.Num.log10 }
multi sub sin($x, $base = 'radians') { $x.sin($base) }

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

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

our Num sub rand (*@args) {
die "too many arguments passed - 0 params expected" if @args;
Expand Down
13 changes: 5 additions & 8 deletions src/setting/Complex.pm
Expand Up @@ -27,7 +27,11 @@ class Complex {
multi method sin($base = 'radians') {
$.re.sin($base) * $.im.cosh($base) + ($.re.cos($base) * $.im.sinh($base))i;
}


multi method asin($base = 'radians') {
-1i * log((self)i + sqrt(1 - self * self));
}

multi method cos($base = 'radians') {
$.re.cos($base) * $.im.cosh($base) - ($.re.sin($base) * $.im.sinh($base))i;
}
Expand Down Expand Up @@ -217,11 +221,4 @@ multi sub exp(Complex $x) {
$x.exp()
}

multi sub sin(Complex $x) {
$x.sin();
}
multi sub sin(Complex $x, $base) {
$x.sin($base);
}

# vim: ft=perl6
2 changes: 1 addition & 1 deletion src/setting/Num.pm
Expand Up @@ -270,7 +270,7 @@ class Num is also {
}
}
our Num multi method sin($base = 'radians') is export {
our Num multi method sin($base = 'radians') {
my $x = self!to-radians($base);
Q:PIR {
$P0 = find_lex "$x"
Expand Down

0 comments on commit f52e459

Please sign in to comment.