Home »
C++ programming language
isinf() Function with Example in C++
C++ isinf() function: Here, we are going to learn about the isinf() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on May 17, 2020
C++ isinf() function
isinf() function is a library function of cmath header, it is used to check whether the given value is infinite (negative infinity or positive infinity). It accepts a value (float, double or long double) and returns 1 if the given value is an infinity; 0, otherwise.
Syntax
Syntax of isinf() function:
In C99, it has been implemented as a macro,
macro isinf(x)
Syntax
In C++11, it has been implemented as a function,
bool isinf (float x);
bool isinf (double x);
bool isinf (long double x);
Parameter(s)
- x – represents the value to be checked whether x is an infinity or not.
Return value
The returns type of this function is bool, it returns 1 if x is an infinity; 0, otherwise.
Sample Input and Output
Input:
float x = 10.0f/0.0f;
Function call:
isinf(x);
Output:
1
Example
C++ code to demonstrate the example of isinf() function:
// C++ code to demonstrate the example of
// isinf() function
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "isinf(1.0f/0.0f) : " << isinf(1.0f / 0.0f) << endl;
cout << "isinf(-1.0f/-0.0f): " << isinf(-1.0f / -0.0f) << endl;
cout << "isinf(0.0/1.0) : " << isinf(0.0 / 1.0) << endl;
cout << "isinf(1.0/0.0) : " << isinf(1.0 / 0.0) << endl;
float x = 10.0f;
// checking using the condition
if (isinf(x)) {
cout << x << " is infinite value." << endl;
}
else {
cout << x << " is not infinite value." << endl;
}
x = 10.0f / 0.0f;
if (isinf(x)) {
cout << x << " is infinite value." << endl;
}
else {
cout << x << " is not infinite value." << endl;
}
return 0;
}
Output
isinf(1.0f/0.0f) : 1
isinf(-1.0f/-0.0f): 1
isinf(0.0/1.0) : 0
isinf(1.0/0.0) : 1
10 is not infinite value.
inf is infinite value.
Reference: C++ isinf() function