Testing for NaN

George Russell ger@tzi.de
Wed, 23 Apr 2003 13:32:37 +0200


The standard trick would be:

   isNaN d = (d /= d)

This will not distinguish between quiet and signalling NaN's,
on the other hand I wonder why on earth you might be getting
signalling NaN's anyway.

(A signalling NaN normally corresponds to "badly formatted
float".  Some compilers give float values initial values of
signalling NaN, to make it clear they haven't been
initialised; the only other reason I can think of why your
program might start having signalling NaNs is because of a
cast from some other type.  I don't think any arithmetic
operations should emit a signalling NaN, unless it was
given one.)