Occasionally you need to check whether a float is a valid number. There are times, such as when the number is read in to a function as an argument, when you can’t assume that the check has already been done. This check can be done using the isnan(number) function from math.h.

For example:

#include <math.h>
...
if(isnan(1.0 / 0.0) {
printf("Not a number\n");
}

  1. Altug says:

    Thank you, I was looking for something like that.

  2. Louis says:

    Thanks, very useful!