Confusion on NaN in Java

后端 未结 4 1124
深忆病人
深忆病人 2020-12-29 08:22
int i = 0, j = 0;
double nan1 = (double)0/0;
double nan2 = (double)0/0;
double nan3 = (double)i/j;
System.out.println(Double.doubleToRawLongBits(nan1) == Double.doub         


        
4条回答
  •  [愿得一人]
    2020-12-29 08:54

    I think Java follows IEEE 754. In this case NaN has more than one possible bit representation. The two representations in your case differ in the "sign" bit. The value of the sign bit seems to be not defined by the standard and is usually ignored. So both values are correct. See http://en.wikipedia.org/wiki/NaN

提交回复
热议问题