> The Fortran standard says the result is supposed to be the principal value, which is +2i.
The exact phrase is
"the principal value with the real part greater than or equal to zero."
In other words, there are 2 principal values.
This is consistent with the DLMF (NIST) term "closed definition of the principal value":
http://dlmf.nist.gov/4.2#i
The link is for the natural logarithm, but the same logic
should apply for SQRT, because
SQRT( z ) = EXP( LOG( z ) / 2 ).
Anyway, the correct answer for SQRT( CMPLX( -4, -0 )) must be (0,-2) as long
as the processor can distinguish +0 and -0.
Anton
P.S. This wasn't an abstract example. A colleague was trying
to understand why Matlab and Fortran gave the answers of opposite sign
for this expression.
|