On Aug 16, 2016, at 8:43 AM, Anton Shterenlikht <[log in to unmask]> wrote:
> Is the correct answer from
>
> sqrt( cmplx( -4.0, -0.0 ))
>
> 1. (0,-2)
> 2. (0,2)
> 3. both 1. and 2.
> 4. either 1. or 2. depending on the compiler flags
>
> Different compilers give different results.
>
> 16-007r1:
>
> Sec. 4.4.3.2p3 [56:21-25]:
> "Processors that distinguish between positive and
> negative zeros shall treat them as mathematically
> equivalent ... as actual arguments to intrinsic
> procedures other than those for which it is explicitly
> specified that negative zero is distinguished".
>
> Sec. 13.9.182p5 [424:7-8], SQRT(X):
> "When the real part of the result is zero, the
> imaginary part has the same sign as the imaginary
> part of X”.
Interesting example. The square root of -4 is either 2i or -2i. (Or +-2j if you are an electrical engineer). The Fortran standard says the result is supposed to be the principal value, which is +2i. That seems to contradict the sentence above, which allows -2i. No surprise there are contradictory vendor results.
Cheers,
Bill
>
> Sec. 13.9.176 [422:7-8], SIGN(A,B):
> "if the processor distinguishes between positive and
> negative real zero, and B is negative real zero,
> the value of the result is -|A|".
>
> So SQRT does not explicitly specify that negative
> zero is distinguished. However, does the word "sign"
> in [424:8] mean as if intrinsic SIGN were applied
> to determine the sign of the imaginary part of X?
>
> SIGN does specify explicitly
> that negative zero is distinguished.
>
> So on processors which distinguish positive and
> negative zero, SQRT *must* distinguish
> negative and positive zero.
> Does this mean that on such processors the
> correct answer is only (1)?
>
> On processors which do not distinguish
> negative and positive zero, sign -0.0
> is positive. So I guess that means the correct
> answer must be only (2)?
>
> Thanks
>
> Anton
Bill Long [log in to unmask]
Fortran Technical Support & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
|