isnan - C math.h

C examples for math.h:isnan

type

macro/function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns whether x is a NaN (Not-A-Number) value, such as the square root of negative numbers or the result of 0/0.

Prototype

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

Parameters

Parameter Description
x A floating-point value.

Return value

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

Example

Demo Code


#include <stdio.h>
#include <math.h> /* isnan, sqrt */

int main()/*ww w  .  j  av  a 2 s. c  o  m*/
{
  int a = 0;
  printf ("%d\n",isnan(0.0));
  printf ("%d\n",isnan(1.0/a));
  printf ("%d\n",isnan(-1.0/a));
  printf ("%d\n",isnan(sqrt(-1.0)));
  return 0;
}

Related Tutorials