home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / fortran / 3053 < prev    next >
Encoding:
Internet Message Format  |  1992-08-16  |  1.8 KB

  1. Path: sparky!uunet!dtix!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!laphroaig!cflatter
  2. From: cflatter@nrao.edu (Chris Flatters)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: how to quit on an NaN result?
  5. Message-ID: <1992Aug16.212321.24278@nrao.edu>
  6. Date: 16 Aug 92 21:23:21 GMT
  7. References: <1992Aug16.200837.14024@samba.oit.unc.edu>
  8. Sender: news@nrao.edu
  9. Reply-To: cflatter@nrao.edu
  10. Organization: NRAO
  11. Lines: 37
  12.  
  13. In article 14024@samba.oit.unc.edu, Bruce.Scott@bbs.oit.unc.edu (Bruce Scott) writes:
  14. >  I am debugging code which is still in the stage where many NaN results
  15. >arise. The problem is that, beyond the waste of time in general,
  16. >operations involving these critters are very slow. How can I check for
  17. >NaN's and quit when one arises. Does one use
  18. >        if (avar .eq. 'NaN') stop
  19. >or is this illegal?
  20.  
  21. I assume that this refers to NaNs in a floating-point implementation that
  22. conforms to IEEE-754.
  23.  
  24. 1) It is legal to compare numbers that are unordered with respect to one
  25.    another (ie. where one or more is a NaN) using .EQ. or .NE..
  26.  
  27. 2) A NaN is not equal to any number even if that number is another NaN.
  28.    A NaN is not even equal to itself.
  29.  
  30. It follows from this that we can test whether a floating-point variable
  31. X contains a NaN as follows.
  32.  
  33.     IF (X.NE.X) THEN
  34. C          X is a NaN
  35.     ELSE
  36. C       X is not a NaN
  37.     END IF
  38.  
  39. Note:
  40. If you want to abort a program after an illegal operation it may be less
  41. disruptive to install a trap handler for the invalid operation exception.
  42. There is no standard way of doing this so you will have to consult your
  43. local documentation.  Some IEEE-754 floating-point implementations do not
  44. allow trap handlers to be installed: this is allowed by the standard but
  45. implementations that do not allow the installation of trap handlers are
  46. substandard IMHO.
  47.  
  48.     Chris Flatters
  49.     cflatter@nrao.edu
  50.