Float.NaN == Float.NaN
2022-09-01 12:20:11
为什么这种比较会给我“假”?我查看了源代码,Float.NaN被定义为
/**
* A constant holding a Not-a-Number (NaN) value of type
* <code>float</code>. It is equivalent to the value returned by
* <code>Float.intBitsToFloat(0x7fc00000)</code>.
*/
public static final float NaN = 0.0f / 0.0f;
编辑:令人惊讶的是,如果我这样做:
System.out.println("FC " + (Float.compare(Float.NaN, Float.NaN)));
它给了我.所以认为NaN等于自己!0
Float.compare()