How to detect NaN's

Michael Meissner meissner at osf.org
Sat Jun 1 08:30:39 AEST 1991


In article <1991May30.204332.16506 at litwin.com> vlr at litwin.com (Vic
Rice) writes:

| I have encountered a problem on a DECStation 5000 using the Mips Fortran
| compiler. Some operation I am performing is generating a NaN which then
| proceeds to propogate to other dependent variables. Since this is in
| a loop, I am not exactly sure where it starts.
| 
| How can I test a variable for the presence of a NaN or Infinity ???

To test for a NaN, simply compare the nubmer against itself.  If it's
a NaN, it will not compare equal.

To test for infinity, I would use (1. / 0.), since division by 0 of
anything but zero gives an infinity with the appropriate sign.  Zero
divided by zero, gives Nan.

Of course there are problably compilers out there that 'optimize' away
such tests, or complain if compile time arithmetic has a division by
zero in it.
--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

You are in a twisty little passage of standards, all conflicting.



More information about the Comp.unix.ultrix mailing list