diff options
author | Perl 5 Porters <perl5-porters@africa.nicoh.com> | 1996-09-08 00:40:34 +0000 |
---|---|---|
committer | Andy Dougherty <doughera@lafcol.lafayette.edu> | 1996-09-08 00:40:34 +0000 |
commit | 3f193590c5874b4c5b016955e0e787f60536c0dc (patch) | |
tree | 64ec0c91e25e63015756d8f898c8b821b56a56c1 /lib/Math | |
parent | 5a13742daee9596f29612f9436636edef76512f1 (diff) | |
download | perl-3f193590c5874b4c5b016955e0e787f60536c0dc.tar.gz |
perl 5.003_05: lib/Math/Complex.pm
There was a mistake in the sqrt routine in lib/Math/Complex.pm that
gave wrong answers when the magnitude of the imaginary part of the
argument exceeded the magnitude of the real part. Line 69 had too
many sqrt($y)'s. Further, expressions were re-arranged so that
calls to the expensive real sqrt() routine were reduced from 4 to 2
in this case.
Diffstat (limited to 'lib/Math')
-rw-r--r-- | lib/Math/Complex.pm | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/Math/Complex.pm b/lib/Math/Complex.pm index 969f3c2c79..2a571aa7e4 100644 --- a/lib/Math/Complex.pm +++ b/lib/Math/Complex.pm @@ -62,11 +62,11 @@ use overload $y = abs($zi); if ($x >= $y) { $r = $y/$x; - $w = sqrt($x) * sqrt(0.5*(1.0+sqrt(1.0+$r*$r))); + $w = sqrt(0.5 * $x * (1.0+sqrt(1.0+$r*$r))); } else { $r = $x/$y; - $w = sqrt($y) * sqrt($y) * sqrt(0.5*($r+sqrt(1.0+$r*$r))); + $w = sqrt(0.5 * ($x + $y*sqrt(1.0+$r*$r))); } if ( $zr >= 0) { @$c = ($w, $zi/(2 * $w) ); @@ -110,7 +110,7 @@ sub stringify { $re = $x if ($x); if ($y == 1) {$im = 'i';} elsif ($y == -1){$im = '-i';} - elsif ($y) {$im = "${y}i"; } + elsif ($y) {$im = $y . 'i'; } local $_ = $re.'+'.$im; s/\+-/-/; |