isinf() function in C++
This function is defined in <cmath.h> .The isinf() function is use to determine whether the given number is infinity or not i.e positive infinity or negative infinity both. This function returns 1 if the given number is infinite otherwise this function returns zero.
Syntax:
bool isinf( float arg );
or
bool isinf( double arg );
or
bool isinf( long double arg );
Parameter: This function takes a mandatory parameter x which represents the given floating point value.
Return: This function returns 1 if the given number is infinite else return zero.
Below programs illustrate the isinf() function in C++:
Example 1:- To show infinite case which returns 1
// c++ program to demonstrate // example of isnormal() function. #include <bits/stdc++.h> using namespace std; int main() { float f = 6.0F; // check for +ve infinite value cout << "isinf(6.0/0.0) is = " << isinf(f/0.0) << endl; // check for -ve infinite value f = -1.2F; cout << "isinf(-1.2/0.0) is = " << isinf(f/0.0) << endl; return 0; } |
isinf(6.0/0.0) is = 1 isinf(-1.2/0.0) is = 1
Explanation: In example 1 the floating point number represents infinity that’s why function returns 1.
Example 2:- To show non-infinite case which returns 0
// c++ program to demonstrate // example of isinf() function. #include <bits/stdc++.h> using namespace std; int main() { cout << "isinf(0.0) is = " << isinf(0.0) << endl; cout << "isinf(sqrt(-1.0)) is = " << isinf(sqrt(-1.0)) << endl; return 0; } |
isinf(0.0) is = 0 isinf(sqrt(-1.0)) is = 0
Exception: In example 2 the given floating point number is not representing infinity that’s why function returns zero.
Recommended Posts:
- Function Overloading vs Function Overriding in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- log() function in C++
- exp() function C++
- fma() function in C++
- div() function in C++
- scalbln() function in C++ STL
- map lower_bound() function in C++ STL
- map count() function in C++ STL
- map erase() function in C++ STL
- map find() function in C++ STL
- map emplace_hint() function in C++ STL
- set lower_bound() function in C++ STL
- set upper_bound() function in C++ STL
- set insert() function in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



