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

Math Isfinite Function

BLUF: Mastering Math Isfinite 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 Isfinite Function

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

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:

Example

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.

Example

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

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.

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:

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.

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<<"isfinite(x) : "<<isfinite(x);
    return 0;
}

Output:

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.

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