C was the computer language that I seriously began programming with. Before c, I had used basic to code few games for myself. But after my first job, I began with c. Then Fortran entered my life and ever since it has dominated my work.
Recently a friend asked me to code a simple routine which checks if the number is nan or not a nan. So I dipped my feet in c.
Here’s the little program i came up with lots of help and blessings of wikipedia..🙂
So here’s the program listing of simple isNAN function in c!!
void myisnan(float x);
int i=0, j=0, nan_count=0;
float x ,y;
x = y/0.0;
void myisnan(float x)
int exp, man;
temp = (int*)&x;
exp = *temp & 0x7f800000; // Extract the exponent;
man = *temp & 0x7fffff; // Extract the mantissa;
if ((exp == 0x7f800000) && (man != 0))
printf("\n%f – We found NAN\n ",x);
printf("\nHey %f – is not NAN\n",x);