Difference between revisions of "CPP/NAN"
From ProgrammingExamples
< CPP
Line 26: | Line 26: | ||
//return false; | //return false; | ||
− | return a!=a; <- like that | + | return a!=a; // <- like that |
} | } | ||
</source> | </source> |
Latest revision as of 16:28, 3 July 2010
NAN.cpp
#include <iostream> #include <limits> using namespace std; bool IsNaN(const double a); int main(int argc, char *argv[]) { double a = numeric_limits<double>::quiet_NaN(); double b = 20; cout << "Is a NAN? " << a << " " << IsNaN(a) << endl; cout << "Is b NAN? " << b << " " << IsNaN(b) << endl; return 0; } bool IsNaN(const double a) { //if(a!=a) <- this is already a bool, why not return it ? //{ // return true; //} //return false; return a!=a; // <- like that }