C Data Type Functions - C isnan






Prototype C99

The C99 prototype is listed as follows.

          macro isnan(x) 

Prototype C++11

The C++11 prototype is listed as follows.

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

Returns whether x is a NaN ( Not-A-Number) value.

Parameter

This function has the following parameter.

x
A floating-point value.

Return

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

Example


#include <stdio.h> /* printf */
#include <math.h> /* isnan, sqrt */
//  w  ww  .  j  a  va2s  . c o m
int main()
{
  printf ("isnan(0.0) : %d\n",isnan(0.0));
  printf ("isnan(sqrt(-1.0)): %d\n",isnan(sqrt(-1.0)));
  return 0;
} 

       

The code above generates the following result.





Example 2


#include <stdio.h>
#include <math.h>
#include <float.h>
 /*w  ww .  j  ava  2s .co  m*/
int main(void)
{
    printf("isnan(NAN)         = %d\n", isnan(NAN));
    printf("isnan(INFINITY)    = %d\n", isnan(INFINITY));
    printf("isnan(0.0)         = %d\n", isnan(0.0));
    printf("isnan(DBL_MIN/2.0) = %d\n", isnan(DBL_MIN/2.0));
    printf("isnan(Inf - Inf)   = %d\n", isnan(INFINITY - INFINITY));
}

The code above generates the following result.