Math Isinf Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Isinf Function

Math Isinf Function

BLUF: Mastering Math Isinf Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Isinf Function

C++ is renowned for its efficiency. Learn how Math Isinf Function enables low-level control and high-performance computing in the tutorial below.

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:

Example

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.

Example

#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:

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.

Example

#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:

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.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience