isfinite() function in C++
The isfinite() function is a builtin function in C++ and is used to determine whether a given value if finite or not. A finite value is a value that is neither infinite nor NAN. If the number is finite then the function returns 1 else returns zero.
Syntax:
bool isfinite(float x); or, bool isfinite(double x); or, bool isfinite(long double x);
Parameter: This function takes only one parameter
. It represents the floating point number.
Returns: If the number is infinite or NAN then it returns 0 else if it is finite then it returns 1.
Below programs illustrate the isfinite() function in C++:
Program 1:
// C++ program to illutrate the // isfinite() function. #include <bits/stdc++.h> using namespace std; int main() { float x = 19.0; cout<<"The value of x is = "<< x << endl; // Here function check whether 19 is finite or not // if yes function returns 1, else 0 cout<<"isfinite(x) = "<<isfinite(x); return 0; } |
The value of x is = 19 isfinite(x) = 1
Program 2:
// C++ program to illutrate the // isfinite() function #include <bits/stdc++.h> using namespace std; int main() { float x=9.6/0.0; cout<<"The value of x is = "<< x << endl; cout<<"isfinite(x) = "<<isfinite(x); return 0; } |
The value of x is = inf isfinite(x) = 0
Program 3:
// C++ program to illutrate the // isfinite() function #include <bits/stdc++.h> using namespace std; int main() { // Value is NAN double x=0.0/0.0; cout<<"Value of x is = "<< x << endl; cout<<"isfinite(x) = "<<isfinite(x); return 0; } |
Value of x is = -nan isfinite(x) = 0
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++
- div() function in C++
- fma() function in C++
- mbsinit() Function in C/C++
- iswctype() function in C/C++
- strtoimax() function in C++
- wctype() function in C/C++
- vswprintf() function in C/C++
- bit_and function in C++
- strtoumax() function in C++
- mbsrtowcs() function in C/C++
- wcspbrk() function in C/C++
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.



