How to test if float is NaN?

Walter Bright newshound at digitalmars.com
Wed May 24 21:32:35 PDT 2006


Don Clugston wrote:
>> Since by definition a NaN is not equal to anything, including itself, 
>> I suppose it's a compiler bug?
> 
> Definitely. I've seen that sort of behaviour before in VC++.
> <cynic> Does anyone at Microsoft understand floating point arithmetic? 
> </cynic>

At least up until VC6, it did not check the parity bit for floating 
point comparisons (the P bit is set if one of the operands is NaN). In 
fact, I know of no C++ compiler other than DMC++ that does this correctly.

VC dropping support for 80 bit long doubles is not an encouraging sign.

This is typical for C++ compiler vendors. Handling of NaN arguments to 
the math.h functions is routinely erratic and buggy. This can be traced 
back to the Standards committee, who failed to specify NaN behavior.



More information about the Digitalmars-d-learn mailing list