J3/03-155
To: J3
From: John Reid
Subject: Treatment of signed zeros by ATAN2, LOG, and SQRT
Date: 14 March 2003
There is a small problem with the wording of the intrinsics ATAN2, LOG,
and SQRT with respect to their treatment of signed zeros. The text was
written before there was any thought of support for IEEE arithmetic and
is fine for nonzero arguments. Wherever possible, the value for a
signed zero should be the limit of those for small values of the same
sign. The wording should allow implementors to do the right thing
(which my tests show that they mainly are at the moment).
For ATAN2(Y,X), there is a problem when X is negative. If Y is very
small and positive, the result is near pi; if Y is very small and
negative, the result is near -pi. It follows that if Y is plus zero,
the result should be approximately pi and if Y is minus zero, the
result should be approximately -pi. Unfortunately, the present wording
says that the result is pi in both cases.
There is a corresponding problem for the imaginary part of LOG(X) when
X is complex with a negative real part. If the imaginary part of X is
plus zero, the imaginary part of the result should be approximately pi
and for minus zero, it should be approximately -pi. The present wording
says that the result is pi in both cases.
There is a similar problem for the imaginary part of SQRT(X) when X is
complex with negative real part. If the imaginary part of X is small and
positive, the imaginary part of the result should be positive
and if it is small and negative, the imaginary part of the result
should be negative. This should also be so for signed zeros,
but the present wording says that the the imaginary part of the result
is positive in both cases.
These edits remove the text that requires the processor to provide the
wrong results for these very special cases. They do not specify exactly
what result should be returned. This is consistent with the tradition
of allowing good values but not requiring this. It is also consistent
with the present wording of several other intrinsics including SIN,
TAN, ASIN, and ATAN.
I also propose that we remove the general requirement that the
intrinsics should not take account of the sign of zero.
EDITS
3:20+. Add
3) If the processor can distinguish between positive and
negative real zero, it is permitted by this standard to return the
result -pi for ATAN2(X,-0.0) when X is negative, -pi for the
imaginary part of LOG(CMPLX(X,-0.0)) when X is negative, and a
negative imaginary part for SQRT(CMPLX(X,-0.0)) when X is
negative.
35:28. Change comma to 'and'.
35:29-30. Delete item (2).
35:31. Change '(3) to '(2)'.
301:26. Replace < by <=.
301:27-28. Delete the sentence 'If Y = 0, ...'.
324:14. Replace < by <=.
324:15-16. Delete the sentence 'The imaginary part ...' .
347:20-21. Delete the sentence 'When the real ...' .