How to use isinf() function to check whether floating point number is an infinity value in C++

1 Answer

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

using namespace std;

int main()
{
	cout << "isinf(0.0)      =  " << isinf(0.0) << endl;
	cout << "isinf(NAN)      =  " << isinf(NAN) << endl;
	cout << "isinf(INFINITY) =  " << isinf(INFINITY) << endl;
	cout << "isinf(1.0)      =  " << isinf(1.0) << endl;
	cout << "isinf(exp(710)) =  " << isinf(exp(710)) << endl;

	return 0;
}

// Return non-zero if x is an infinity, and zero otherwise

/*
run:

isinf(0.0)      =  0
isinf(NAN)      =  0
isinf(INFINITY) =  1
isinf(1.0)      =  0
isinf(exp(710)) =  1

*/

 



answered Mar 19, 2016 by avibootz
...