Xref: utzoo comp.unix.ultrix:7445 comp.lang.fortran:5564 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!think.com!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.unix.ultrix,comp.lang.fortran Subject: Re: How to detect NaN's Message-ID: Date: 31 May 91 22:30:39 GMT References: <1991May30.204332.16506@litwin.com> Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 25 In-reply-to: vlr@litwin.com's message of 30 May 91 20:43:32 GMT In article <1991May30.204332.16506@litwin.com> vlr@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@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.