How to use isfinite() function to check if the given floating point number has finite value in C++

1 Answer

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

using namespace std;

int main()
{
	cout << "isfinite(NAN) = " << isfinite(NAN) << endl;
	cout << "isfinite(INFINITY) = " << isfinite(INFINITY) << endl;
	cout << "isfinite(0.0) = " << isfinite(0.0) << endl;	
	cout << "isfinite(0.0 / 2.0)  = " << isfinite(0.0 / 2.0) << endl;
	cout << "isfinite(1.0) = " << isfinite(1.0) << endl;

	return 0;
}


/*
run:

isfinite(NAN) = 0
isfinite(INFINITY) = 0
isfinite(0.0) = 1
isfinite(0.0 / 2.0)  = 1
isfinite(1.0) = 1

*/

 



answered Mar 19, 2016 by avibootz
...