Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Feb 3, 2023
Contribute to Docs

The isinf() function returns a value indicating whether or not the argument is an infinite value.



The x parameter is a floating-point value. If x is infinite, the isinf() function will return a non-zero value for true. Otherwise, it will return zero for false.

Examples of positive or negative infinite values include division by zero.


The following example uses the isinf() function to check whether 1.0 is infinite:

#include <iostream>
#include <cmath>
int main() {
int result;
result = std::isinf(1.0);
if (result == 0) {
std::cout << "Not infinite" << "\n";
else {
std::cout << "Is infinite" << "\n";

This produces the following output:

Not infinite

Codebyte Example

The following example is runnable and prints a message based on whether the isinf() function indicates a given value is finite or infinite:


All contributors

Looking to contribute?

Learn C++ on Codecademy