🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #11125

Testing for NaN in Think C (help!)

#11125
From: Melissa Hines
Date: Mon, 26 Mar 1990 19:40
30 lines
1483 bytes
I've got a quick Think C question: How do you test for NaN (Not A Number) in
Think C?  It is very easy to generate NaN:
    float Nan;
    NaN = 0.0/0.0;
It is not as easy to test for it however.  For example, the following does not
work:
    float test,NaN;
    NaN = 0.0/0.0;
    if (test == NaN)
        ;
      else
        ; /* I always break to this loop, not the one above regardless of what
                I set test to. */
The following does work, but is pretty ugly:
    if((test/test != 1) && (test != 0))
        ; /* Here if NaN */
      else
        ; /* Here otherwise */
Is there a simpler/ more elegant way of doing this?  I think part of the
problem is that the IEEE have decreed that the result of any operation on
a NaN is a Nan.  Also, I think Think C may have more than one type of NaN. I
couldn't care less about the type, I just want to know if it is a NaN.

Thanks for your help!

Melissa Hines
Dept. of Chemistry
Stanford Univ.
Hines@Portia.Stanford.Edu
Hines@Cellbio.Stanford.Edu
Technical Details
Message-ID: <10538@portia.Stanford.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ogicse!decwrl!shelby!portia!hines

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ogicse!decwrl!shelby!portia!hines
From: hines@portia.Stanford.EDU (Melissa Hines)
Newsgroups: comp.sys.mac
Subject: Testing for NaN in Think C (help!)
Message-ID: <10538@portia.Stanford.EDU>
Date: 26 Mar 90 19:40:07 GMT
Sender: Melissa Hines <hines@portia.stanford.edu>
Reply-To: hines@portia.Stanford.EDU (Melissa Hines)
Organization: Stanford University
Lines: 29