C Data Type Functions - C isfinite






Returns whether x is a finite value.

Prototype C99

The C99 prototype is listed as follows.

macro isfinite(x) 

Prototype C++11

The C++11 prototype is listed as follows.

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

Parameter

This function has the following parameter.

x
A floating-point value.

Return

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

Example


#include <stdio.h> /* printf */
#include <math.h> /* isfinite, sqrt */
//from   ww  w  . jav  a2 s .  co  m
int main()
{
  printf ("isfinite(0.0) : %d\n",isfinite(0.0));
  printf ("isfinite(sqrt(-1.0)): %d\n",isfinite(sqrt(-1.0)));
  return 0;
} 

       

The code above generates the following result.





Example 2


#include <stdio.h>
#include <math.h>
#include <float.h>
 //from   w w  w  .  j ava  2 s . co  m
int main(void)
{
    printf("isfinite(NAN)         = %d\n", isfinite(NAN));
    printf("isfinite(INFINITY)    = %d\n", isfinite(INFINITY));
    printf("isfinite(0.0)         = %d\n", isfinite(0.0));
    printf("isfinite(DBL_MIN/2.0) = %d\n", isfinite(DBL_MIN/2.0));
    printf("isfinite(1.0)         = %d\n", isfinite(1.0));
    printf("isfinite(exp(800))    = %d\n", isfinite(exp(800)));
}

The code above generates the following result.