home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / next / programm / 7357 < prev    next >
Encoding:
Internet Message Format  |  1992-11-21  |  1.2 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!news.cs.indiana.edu!arizona.edu!arizona.edu!news
  2. Newsgroups: comp.sys.next.programmer
  3. Subject: Re: trapping NaN
  4. Message-ID: <1992Nov21.111335.4014@arizona.edu>
  5. From: zazula@pri.com (Ralph Zazula)
  6. Date: 21 Nov 92 11:13:35 MST
  7. Reply-To: zazula@pri.com
  8. References: <1992Nov20.221038.1170@proforma.com>
  9. Distribution: world,local
  10. Nntp-Posting-Host: bonehead.tucson.az.us
  11. Lines: 31
  12.  
  13. In article <1992Nov20.221038.1170@proforma.com>  writes:
  14. > I would like to trap NaN -- the "not a number" condition that floating point  
  15. > values can take.  I can't find any clue on how to do this, except some  
  16. cryptic  
  17. > stuff in the man pages under "math".  Is there some signal I can handle?
  18. > Thanks in advance.
  19. > --J Gregory
  20.  
  21. Hi -
  22.  
  23. It turns out that (NaN != NaN) is true.  So, in some code I did before, I used:
  24.  
  25. if(x == x) {    /* x is NOT NaN */
  26. < use x>
  27. }
  28. else {
  29. <whatever for the NaN case>
  30. }
  31.  
  32. Here's the excerpt from the manual page:
  33.  
  34. "If x != x then x is NaN; every other predicate (x > y, x = y, x < y,...) is  
  35. FALSE if NaN is involved."
  36.  
  37. Ralph
  38. ---
  39. Ralph Zazula
  40. Pinnacle Research, Inc.
  41. zazula@pri.com (NeXT Mail)
  42. (602)529-1135
  43.