#include <limits>

using namespace std;

const double double_nan = numeric_limits<double>::quiet_NaN();

double x = double_nan;

if (x == double_nan) cout << "OK" << endl;

I dont get OK! Why?

#include <limits>

using namespace std;

const double double_nan = numeric_limits<double>::quiet_NaN();

double x = double_nan;

if (x == double_nan) cout << "OK" << endl;

I dont get OK! Why?

Because a NAN wont compare to anything, even itself. You'd need to check the IEEE standard on floating point numbers for exactly why. (IEEE-754 I think). Simple as that.

commented: Excellent! +19

Correct. NaN is defined mathematically to not be equal to itself.

Ok, thanks, this is a convention, its mathematically logical, but not lcical for a programer, because nan is also a bit series as any other number...

Are there any bool function which gives back true if a number is nan?
(ok I can write it, but are there any built in function?)

I found it pretty easy. Check this link.

I found it pretty easy. Check this link.

Thanks a lot, Fbody....There goes my productivity for this morning...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.