473,408 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Comparison Against NaN

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;
}
}
Jul 10 '08 #1
4 4760
On Jul 10, 2:33*pm, "better_cs_...@yahoo.com"
<better_cs_...@yahoo.comwrote:
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.
Jul 10 '08 #2
On Jul 10, 3:59*pm, "robertwess...@yahoo.com"
<robertwess...@yahoo.comwrote:
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.
Jul 10 '08 #3
On Jul 10, 3:33*pm, "better_cs_...@yahoo.com"
<better_cs_...@yahoo.comwrote:
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
Jul 11 '08 #4
"be***********@yahoo.com" <be***********@yahoo.comkirjutas:
Hello all,

The code below outputs "FALSE" on my platform. Does the language
guarantee this behavior?
If you ask so, then no (the presence of a NaN value is not required by
the standard). However, maybe you wanted to ask another question: does
the language guarantee that comparing NaN with itself yields false; in
this case, the answer is yes, these comparison rules are part of the
definition of a NaN.

hth
Paavo
>
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;
}
}
Jul 13 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roman Yakovenko | last post by:
> From: Alex Martelli > > Roman Yakovenko <roman.yakovenko@actimize.com> wrote: > > > Thanks. I have an other question, more general: > > > > I have class A that defines __eq__ and __ne__....
0
by: Megan | last post by:
Data Comparison: Sample Versus Rest of Population. I have a population of data, and I want to take a sample of that population and compare it against the entire population. I have a database...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
43
by: michael.f.ellis | last post by:
The following script puzzles me. It creates two nested lists that compare identically. After identical element assignments, the lists are different. In one case, a single element is replaced. In...
7
by: bcutting | last post by:
I am looking for a way to take a large number of images and find matches among them. These images may not be exact replicas. Images may have been resized, cropped, faded, color corrected, etc. ...
7
by: matt | last post by:
hello, i have been given a challenging project at my org. i work on an inventory management web application -- keeping tracking of parts assigned to projects. in the past, i built an in-house...
11
by: Steven D'Aprano | last post by:
I'm writing a class that implements rich comparisons, and I find myself writing a lot of very similar code. If the calculation is short and simple, I do something like this: class Parrot: def...
1
by: Lars B | last post by:
Hey guys, I have written a C++ program that passes data from a file to an FPGA board and back again using software and DMA buffers. In my program I need to compare the size of a given file against...
2
by: rhaazy | last post by:
I need to know how I can format a string in C# to get the current date/ time, so that I can do a comparison against a date time column in MS SQL Server 2005. The date/time column in the database...
37
by: Michele Simionato | last post by:
At work we are shopping for a Web framework, so I have been looking at the available options on the current market. In particular I have looked at Paste and Pylons and I have written my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.