Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The C++ <cmath> isinf() function returns true if the given argument is an infinity value (either positive infinity or negative infinity), else returns false.

Syntax

bool isinf (float x);
bool isinf (double x);
bool isinf (long double x);               

Parameters

x Specify a floating-point value.

Return Value

Returns true (non-zero value) if the argument is an infinity value, else returns false (zero value).

Example:

The below example shows the usage of isinf() function.

#include <iostream>
#include <cmath>

using namespace std;
 
int main (){

  cout<<boolalpha;
  cout<<"isinf(10.5): "<<isinf(10.5)<<"\n";
  cout<<"isinf(1.0/0.0): "<<isinf(1.0/0.0)<<"\n";
  cout<<"isinf(-1.0/0.0): "<<isinf(-1.0/0.0)<<"\n";
  cout<<"isinf(sqrt(-1.0)): "<<isinf(sqrt(-1.0))<<"\n";
  return 0;
}

The output of the above code will be:

isinf(10.5): false
isinf(1.0/0.0): true
isinf(-1.0/0.0): true
isinf(sqrt(-1.0)): false

❮ C++ <cmath> Library