C Standard Library

C <math.h> - isnan()

The C <math.h> isnan() macro returns true if the given argument is a NaN (Not-A-Number) value, else returns false. A NaN value is used to identify undefined or non-representable values for floating-point elements, for example - the result of 0/0.




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 isnan() macro.

#include <stdio.h>
#include <math.h>
int main (){

  printf("isnan(10.5): %d\n", isnan(10.5));
  printf("isnan(1.0/0.0): %d\n", isnan(1.0/0.0));
  printf("isnan(0.0/0.0): %d\n", isnan(0.0/0.0));
  printf("isnan(sqrt(-1.0)): %d\n", isnan(sqrt(-1.0)));
  return 0;

The output of the above code will be:

isnan(10.5): 0
isnan(1.0/0.0): 0
isnan(0.0/0.0): 1
isnan(sqrt(-1.0)): 1

❮ C <math.h> Library