How to use isnan() function to determine if the given floating point number is a not-a-number (NaN) in C++

1 Answer

0 votes
#include <iostream>
#include <cmath>

using namespace std;

// Return non-zero if x is a NaN and zero otherwise

int main()
{
	cout << "isnan(0.0)        = " << isnan(0.0) << endl;
	cout << "isnan(NAN)        = " << isnan(NAN) << endl;
	cout << "isnan(INFINITY)   = " << isnan(INFINITY) << endl;
	cout << "isnan(INFINITY / -INFINITY) = " << isnan(INFINITY / - INFINITY) << endl;

	return 0;
}

/*
run:

isnan(0.0)        = 0
isnan(NAN)        = 1
isnan(INFINITY)   = 0
isnan(INFINITY / -INFINITY) = 1

*/

 



answered Mar 22, 2016 by avibootz
edited Mar 22, 2016 by avibootz
...