isinf() function in C++


In this article we will be discussing the isinf() function in C++, its syntax, working and what will be its return value.

isinf() is an inbuilt function in C++ which comes under header file, the function is used to check whether the variable passed in it is infinity or not, no matter if the number is negative infinity or positive infinity. If the number is infinite the function returns a non-zero value (true) and if it is not then it passes zero (false). Also if the number is NAN then also the function will return 0.

Syntax

bool isinf(float n);

or

bool isinf(double n);

or

bool isinf(long double n);

This function accepts only one floating point number.

Return value

Function returns boolean value, 0 for false(not infinity) and 1 if it is true(infinite).

Example

 Live Demo

#include <iostream>
#include <cmath>
using namespace std;
int main() {
   float a = 0.0, b = 10.0;
   isinf(a/b)?cout<<"\nInfinte":cout<<"\nFinite"; //check the number is infinte or finite
   isinf(b/a)?cout<<"\nInfinite":cout<<"\nFinite";
}

Output

If we run the above code it will generate the following output −

Finite
Infinite

Example

 Live Demo

#include <iostream>
#include <cmath>
using namespace std; int main() {
   float a = 0.0;
   cout<<isinf(a);
   cout<<isinf(sqrt(-1.0));
}

Output

If we run the above code it will generate the following output −

0 0

Updated on: 28-Feb-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements