Comparison Against NaN

B

better_cs_now

Hello all,

The code below outputs "FALSE" on my platform. Does the language
guarantee this behavior?

Thanks,
Dave


#include <iostream>
#include <limits>

using namespace std;

int main()
{
double Result;

try
{
Result = numeric_limits<double>::quiet_NaN(); // 1.#QNAN

if (Result == numeric_limits<double>::quiet_NaN())
cout << "TRUE" << endl;
else
cout << "FALSE" << endl;
}
catch(...)
{
cout << "Exception!!!" << endl;
}
}
 
R

robertwessel2

Hello all,

The code below outputs "FALSE" on my platform. Does the language
guarantee this behavior?

Thanks,
Dave

#include <iostream>
#include <limits>

using namespace std;

int main()
{
        double Result;

        try
        {
                Result = numeric_limits<double>::quiet_NaN(); // 1.#QNAN

                if (Result == numeric_limits<double>::quiet_NaN())
                        cout << "TRUE" << endl;
                else
                        cout << "FALSE" << endl;
        }
        catch(...)
        {
                cout << "Exception!!!" << endl;
        }



}


C99 does if the implementation defines __STDC_IEC_559__. C89/90 says
nothing about that, although your implementation might, nor does C99
if that macro is not defined.
 
R

robertwessel2

C99 does if the implementation defines __STDC_IEC_559__.  C89/90 says
nothing about that, although your implementation might, nor does C99
if that macro is not defined.


And for some reason I though I was replying in comp.lang.c, not .c+
+...

Anyway, the current C++ standard is in the same boat as C89/90,
although the next standard will (likely) include the C99 IEEE math
support option.
 
J

joseph cook

Hello all,

The code below outputs "FALSE" on my platform. Does the language
guarantee this behavior?
<snip>

No,
But the general idea of all types of NaN is that they always
compare false, even to each other.

Joe Cook
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,155
Messages
2,570,871
Members
47,401
Latest member
CliffGrime

Latest Threads

Top