home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!laphroaig!cflatter
- From: cflatter@nrao.edu (Chris Flatters)
- Newsgroups: comp.lang.fortran
- Subject: Re: how to quit on an NaN result?
- Message-ID: <1992Aug16.212321.24278@nrao.edu>
- Date: 16 Aug 92 21:23:21 GMT
- References: <1992Aug16.200837.14024@samba.oit.unc.edu>
- Sender: news@nrao.edu
- Reply-To: cflatter@nrao.edu
- Organization: NRAO
- Lines: 37
-
- In article 14024@samba.oit.unc.edu, Bruce.Scott@bbs.oit.unc.edu (Bruce Scott) writes:
- > I am debugging code which is still in the stage where many NaN results
- >arise. The problem is that, beyond the waste of time in general,
- >operations involving these critters are very slow. How can I check for
- >NaN's and quit when one arises. Does one use
- > if (avar .eq. 'NaN') stop
- >or is this illegal?
-
- I assume that this refers to NaNs in a floating-point implementation that
- conforms to IEEE-754.
-
- 1) It is legal to compare numbers that are unordered with respect to one
- another (ie. where one or more is a NaN) using .EQ. or .NE..
-
- 2) A NaN is not equal to any number even if that number is another NaN.
- A NaN is not even equal to itself.
-
- It follows from this that we can test whether a floating-point variable
- X contains a NaN as follows.
-
- IF (X.NE.X) THEN
- C X is a NaN
- ELSE
- C X is not a NaN
- END IF
-
- Note:
- If you want to abort a program after an illegal operation it may be less
- disruptive to install a trap handler for the invalid operation exception.
- There is no standard way of doing this so you will have to consult your
- local documentation. Some IEEE-754 floating-point implementations do not
- allow trap handlers to be installed: this is allowed by the standard but
- implementations that do not allow the installation of trap handlers are
- substandard IMHO.
-
- Chris Flatters
- cflatter@nrao.edu
-