C++ Math isinf
The function checks if the number is infinite, whether positive or negative. It will output 1 if the number is infinite, otherwise it will return 0.
Syntax
Suppose a number is 'x'. Syntax would be:
bool isinf(float x);
bool isinf(double x);
bool isinf(long double x);
bool isinf(integral x);
Parameter
x : It is a floating point value.
Return value
| Parameter(x) | Return value |
|---|---|
| Finite value | Infinite value |
0 |
1 |
Example 1
Let's consider a straightforward example where the variable x is assigned the value of 1.0 divided by 0.0.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=1.0/0.0;
cout<<"value of x is : "<<x<<'\n';
cout<<"isinf(x) : "<<isinf(x);
return 0;
}
Output:
value of x is : inf
isinf(x) : 1
In this instance, the isinf function assesses whether the value of x is infinite, and subsequently, it yields a result of 1.
Example 2
Let's consider a basic scenario where the value assigned to x is 4.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=4;
cout<<"value of x is : "<<x<<'\n';
cout<<"isinf(x) : "<<isinf(x);
return 0;
}
Output:
value of x is : 4
isinf(x) : 0
The isinf function in this scenario checks if the variable x is a finite number, resulting in a return value of 0.