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.
$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) );
$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/\+-/-/;