How to produce a NaN float in c?

前端 未结 9 941
春和景丽
春和景丽 2020-12-05 14:01
float f = (float)\'a\';
if(f < 0){ 
}   
else if(f == 0){ 
}   
else if(f > 0){ 
}   
else{
    printf(\"NaN\\n\");                                                     


        
9条回答
  •  我在风中等你
    2020-12-05 14:40

    Following C program will produce a NaN. The second statement will result in a NaN.

    #include 
    #include 
    #include "math.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        double dSQRTValue = sqrt( -1.00 ); 
        double dResult = -dSQRTValue;  // This statement will result in a NaN.
        printf( "\n %lf", dResult );
    
        return 0;
    }
    

    Following will be the output of the program.

    1.#QNAN0

提交回复
热议问题