C++ isfinite()
Published Oct 31, 2022Updated Dec 21, 2022
Contribute to Docs
The isfinite() function returns a value telling whether the argument has a finite value.
Syntax
isfinite(x)
The x parameter is finite if it is a floating-point number that is neither infinite nor NaN (e.g., division by zero, square root of a negative value).
If x is finite, the isfinite() function will return a non-zero value for true. Otherwise, it will return zero for false.
Example
The following example uses the isfinite() function to check whether 5.0 is finite:
#include <iostream>#include <cmath>int main() {int result;result = std::isfinite(5.0);if (result == 0) {std::cout << "Not finite" << "\n";}else {std::cout << "Is finite" << "\n";}// Output: Is finite}
Codebyte Example
The following example is runnable and features a case where running the isfinite() function where the returns false and the value is not finite:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C++ on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
- Beginner Friendly.11 hours