0
#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?

5
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by dusktreader
1
#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.

Edited by mattjbond: n/a

Votes + Comments
Excellent!
0

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...

0

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?)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.