[cfp-interest 3421] Re: sign bit of a NaN

Vincent Lefevre vincent at vinc17.net
Fri Mar 28 19:55:13 PDT 2025


On 2025-03-29 13:18:58 +1100, Damian McGuckin wrote:
> In looking at somebodies example, it was noticed that
> 
> 	const double nan = 0.0/0.0
> 
> delivers
> 
> 	-nan ... with gcc 11
> 	+nan ,,, with clang 17
> 
> I know that the sign is irrelevant on a NaN but with something like cproj()
> whose sign of its imaginary component does depend on this,
> one might get the wrong answer (alough not one which will compare as
> different).
> 
> What should the above yield or is there not an answer to that question?

The sign bit is unspecified in such a case. This may also depend
on the optimization level and the context.

IMHO, it is a bad idea to rely on the sign bit of a NaN, even when
specified.

> Note that
> 
> 	const double inf = 1.0/0.0
> 
> yields +INFINITY with both compilers.

Yes, because zeros and infinities have a real sign, and
in particular, 0.0 has a positive sign.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)


More information about the cfp-interest mailing list