This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Built-in testing for signaling nan?


On Nov 6 2013, FX wrote:

GCC has a number of floating-point-related type-generic built-ins, which are great and which we largely rely on in the gfortran runtime library (rather than depending on the possibly poor-quality target math library).

However, I have not been able to find a way to test for a signaling NaN using the existing built-ins? __builtin_fpclassify() and __builtin_isnan() both return the same thing for quite and signaling NaNs. We have a __builtin_nans() function to generate a signaling NaN, but nothing to find one.

Am I missing something? Would it be hard to implement such a built-in?

Yes, due to the poor quality of the IEEE 754 specifications.  In 1984,
the distinction was left completely unspecified (even in intent).  In
2008, there is a recommendation (no more) that the top bit of the payload
is used, with no specification of what to do if that is zero (which is
the most obvious default).  That appears to be the Intel specification,
though it may not have always been so even for x86.  I have certainly
seen more than one convention for different architectures, but have no
idea how many are extant nor how many are documented in the relevant
architecture manuals.

I don't know how reliable __builtin_nans() is, but a test is potentially
even less reliable.  Simply testing that bit MIGHT work, or it might be
nothing more than a gotcha.


Regards,
Nick Maclaren.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]