C++ Standard Library C++ STL Library

C++ <cmath> - isfinite() Function

The C++ <cmath> isfinite() function returns true if the given argument is a finite value, else returns false. A finite value is any floating-point value that is neither infinity nor NaN (Not-A-Number).


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


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).


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

#include <iostream>
#include <cmath>

using namespace std;
int main (){

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

The output of the above code will be:

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

❮ C++ <cmath> Library