Confusion on NaN in Java

后端 未结 4 1107
深忆病人
深忆病人 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:51

    The reason is because when you divide a double variable 0 by 0 it returns NaN, so the method doesnt have a single canonical representation in binary, so it may return the binary of NaN as 7F F8 00 00 00 00 00 00 or FF F8 00 00 00 00 00 00.

    Even though technically they represent the same thing, which is NaN, its different in binary representation.

提交回复
热议问题