Difference between revisions of "CPP/NAN"
From ProgrammingExamples
< CPP
Daviddoria (Talk | contribs) (Created page with '==NAN.cpp== <source lang="cpp"> #include <iostream> #include <limits> using namespace std; bool IsNaN(const double a); int main(int argc, char *argv[]) { double a = nume…') |
|||
Line 20: | Line 20: | ||
bool IsNaN(const double a) | bool IsNaN(const double a) | ||
{ | { | ||
− | if(a!=a) | + | //if(a!=a) <- this is already a bool, why not return it ? |
− | { | + | //{ |
− | + | // return true; | |
− | } | + | //} |
− | return false; | + | //return false; |
+ | |||
+ | return a!=a; <- like that | ||
} | } | ||
</source> | </source> |
Revision as of 16:27, 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 }