summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Math/Complex.pm23
-rwxr-xr-xt/lib/complex.t12
2 files changed, 19 insertions, 16 deletions
diff --git a/lib/Math/Complex.pm b/lib/Math/Complex.pm
index b13191bf38..daf190e89b 100644
--- a/lib/Math/Complex.pm
+++ b/lib/Math/Complex.pm
@@ -1105,10 +1105,13 @@ sub acosh {
return cplx(0, CORE::atan2(CORE::sqrt(1 - $re*$re), $re))
if CORE::abs($re) < 1;
}
- my $s = &sqrt($z*$z - 1);
- my $t = $z + $s;
- $t = 1/(2*$s) if $t == 0 || $t && &abs(cosh(&log($t)) - $z) > $eps;
- return &log($t);
+ my $t = &sqrt($z * $z - 1) + $z;
+ # Try MacLaurin if looking bad.
+ $t = 1/(2 * $z) - 1/(8 * $z**3) + 1/(16 * $z**5) - 5/(128 * $z**7)
+ if $t == 0;
+ my $u = &log($t);
+ $u->Im(-$u->Im) if $im == 0;
+ return $re < 0 ? -$u : $u;
}
#
@@ -1122,10 +1125,10 @@ sub asinh {
my $t = $z + CORE::sqrt($z*$z + 1);
return CORE::log($t) if $t;
}
- my $s = &sqrt($z*$z + 1);
- my $t = $z + $s;
- # Try Taylor series if looking bad.
- $t = 1/(2*$s) if $t == 0 || $t && &abs(sinh(&log($t)) - $z) > $eps;
+ my $t = &sqrt($z * $z + 1) + $z;
+ # Try MacLaurin if looking bad.
+ $t = 1/(2 * $z) - 1/(8 * $z**3) + 1/(16 * $z**5) - 5/(128 * $z**7)
+ if $t == 0;
return &log($t);
}
@@ -1390,7 +1393,7 @@ sub stringify_polar {
if ($format{polar_pretty_print}) {
my ($a, $b);
- for $a (2, 3, 4, 6, 8, 12, 16, 24, 30, 32, 36, 48, 60, 64, 72) {
+ for $a (2..9) {
$b = $t * $a / pi;
if (int($b) == $b) {
$b = $b < 0 ? "-" : "" if CORE::abs($b) == 1;
@@ -1734,7 +1737,7 @@ For instance:
print "j = $j\n"; # Prints "j = -0.5+0.866025403784439i"
The polar style attempts to emphasize arguments like I<k*pi/n>
-(where I<n> is a positive integer and I<k> an integer within [-9,+9]),
+(where I<n> is a positive integer and I<k> an integer within [-9, +9]),
this is called I<polar pretty-printing>.
=head2 CHANGED IN PERL 5.6
diff --git a/t/lib/complex.t b/t/lib/complex.t
index 7312c09de0..d4beb8bded 100755
--- a/t/lib/complex.t
+++ b/t/lib/complex.t
@@ -892,7 +892,7 @@ __END__
( 2,-3):( 1.96863792579310, -0.96465850440760)
&acosh
-(-2.0,0):( -1.31695789692482, 3.14159265358979)
+(-2.0,0):( 1.31695789692482, 3.14159265358979)
(-1.0,0):( 0, 3.14159265358979)
(-0.5,0):( 0, 2.09439510239320)
( 0.0,0):( 0, 1.57079632679490)
@@ -902,8 +902,8 @@ __END__
&acosh
( 2, 3):( 1.98338702991654, 1.00014354247380)
-(-2, 3):( -1.98338702991653, -2.14144911111600)
-(-2,-3):( -1.98338702991653, 2.14144911111600)
+(-2, 3):( 1.98338702991653, 2.14144911111600)
+(-2,-3):( 1.98338702991653, -2.14144911111600)
( 2,-3):( 1.98338702991654, -1.00014354247380)
&atanh
@@ -922,15 +922,15 @@ __END__
&asech
(-2.0,0):( 0 , 2.09439510239320)
(-1.0,0):( 0 , 3.14159265358979)
-(-0.5,0):( -1.31695789692482, 3.14159265358979)
+(-0.5,0):( 1.31695789692482, 3.14159265358979)
( 0.5,0):( 1.31695789692482, 0 )
( 1.0,0):( 0 , 0 )
( 2.0,0):( 0 , 1.04719755119660)
&asech
( 2, 3):( 0.23133469857397, -1.42041072246703)
-(-2, 3):( -0.23133469857397, 1.72118193112276)
-(-2,-3):( -0.23133469857397, -1.72118193112276)
+(-2, 3):( 0.23133469857397, -1.72118193112276)
+(-2,-3):( 0.23133469857397, 1.72118193112276)
( 2,-3):( 0.23133469857397, 1.42041072246703)
&acsch