float f = (float)\'a\';
if(f < 0){
}
else if(f == 0){
}
else if(f > 0){
}
else{
printf(\"NaN\\n\");
A -nan can also be produced by setting all 32 bits of a float variable as 1, as shown below:
float nan_val = 0xffffffff;
Also, you can compare if a float variable is -nan explicitly by checking if comparison with itself fails.
if (nan_val != nan_val) {
// executes iff nan_val is -nan
}
This method of comparison should work for compilers that use IEEE floats.