C++ Math isfinite
The function assesses whether a value is finite or not, ensuring it is neither NaN nor infinite. If the value is finite, the function will output 1; otherwise, it will return 0.
Note: A finite value is a value that is neither NAN nor infinite.
Syntax
Suppose a number is 'x'. Syntax would be:
bool isfinite(float x);
bool isfinite(double x);
bool isfinite(long double x);
bool isfinite(integral x);
Parameter
x : It is a floating point value.
Return value
| Parameter(x) | Return value |
|---|---|
| Finite value | 1 |
| NAN or infinite value | 0 |
Example 1
Let's examine a straightforward scenario where the value assigned to x equals 10.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x=10;
cout<<"value of x is : "<<x<<'\n';
cout<<"isfinite(x) : "<<isfinite(x);
return 0;
}
Output:
value of x is : 10
isfinite(x) : 1
In this instance, the function infinite assesses the finiteness of the value x, resulting in a return value of 1.
Example 2
Let's see another simple example.
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
double x=0.0/0.0;
cout<<"value of x is : "<<x<<'\n';
cout<<"isfinite(x) : "<<isfinite(x);
return 0;
}
Output:
value of x is : -nan
isfinite(x) : 0
In this instance, the isfinite method establishes that x is a NaN (Not a Number), resulting in a return value of 0.
Example 3
Let's consider a basic scenario where the value of x is 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<<"isfinite(x) : "<<isfinite(x);
return 0;
}
Output:
value of x is : inf
isfinite(x) : 0
In this instance, the function isfinite(x) checks whether x is an infinite number, resulting in a return value of 0.