macro
<cmath> <ctgmath>

isfinite

macro
isfinite(x)
function
bool isfinite (float x);
bool isfinite (double x);
bool isfinite (long double x);
Is finite value
Returns whether x is a finite value.

A finite value is any floating-point value that is neither infinite nor NaN (Not-A-Number).

In C, this is implemented as a macro that returns an int value. The type of x shall be float, double or long double.
In C++, it is implemented with function overloads for each floating-point type, each returning a bool value.

Parameters

x
A floating-point value.

Return value

A non-zero value (true) if x is finite; and zero (false) otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
/* isfinite example */
#include <stdio.h>      /* printf */
#include <math.h>       /* isfinite, sqrt */

int main()
{
  printf ("isfinite(0.0)       : %d\n",isfinite(0.0));
  printf ("isfinite(1.0/0.0)   : %d\n",isfinite(1.0/0.0));
  printf ("isfinite(-1.0/0.0)  : %d\n",isfinite(-1.0/0.0));
  printf ("isfinite(sqrt(-1.0)): %d\n",isfinite(sqrt(-1.0)));
  return 0;
}


Output:

isfinite(0.0)       : 1
isfinite(1.0/0.0)   : 0
isfinite(-1.0/0.0)  : 0
isfinite(sqrt(-1.0)): 0

See also