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.)
cast from some other type. I don't think any arithmetic operations should emit a signalling NaN, unless it was given one.)
According to IEC 60559 (same content as IEEE 754), if conformance is claimed, no arithmetic operation returns a signalling NaN. Given a signalling NaN, an "invalid" bit is set (if not in trapping mode), and a *quiet* NaN is returned. A quiet NaN, on the other hand, does NOT result in the "invalid" bit being set (unless it was already set, or another operand is a signalling NaN). "Errors", like sqrt of a negative value, can also set the "invalid" bit, but returns a quiet NaN. No-one seems to have come up with a really good use for *signalling* NaNs, but seems to be and inheritance from pre-IEEE floating point implementations ("invalid operands")... /kent k
"Kent Karlsson" <kentk@md.chalmers.se> writes: [...] | No-one seems to have come up with a really good use | for *signalling* NaNs, but seems to be and inheritance from pre-IEEE | floating point implementations ("invalid operands")... I've seen a software (written in C) that used signalling NaN to tag "unintialized data". I think that was a case of "good use". -- Gaby
George Russell <ger@tzi.de> writes: | The standard trick would be: | | isNaN d = (d /= d) | | This will not distinguish between quiet and signalling NaN's, if "d" is a signalling NaN, the above may trap. I.e, the only things one can do with a signalling NaN are: (a) change its value; or (b) pass it around. -- Gaby
participants (3)
-
Gabriel Dos Reis -
George Russell -
Kent Karlsson