为什么当 0.0 乘以 -1 时我得到 -0.0??? 我采用 0.0 作为 float
sign=-1;
float output=0.0;
JOptionPane.showmessagedialog(null,0.0*sign);
输出显示为 -0.0 而不是 0
最佳答案
这是来自http://www.javawebtips.com/154041/的答案
"-0.0" Is produced when a floating-point operation results in a negative floating-point number so close to 0 that cannot be represented normally.
-2.0 / Float.POSITIVE_INFINITY -> -0.0
"-0.0" Is numerically identical to "0.0". However, some operations involving "-0.0" are different than the same operation with "0.0".
(-0.0) == 0.0 -> true
2.0 / (0.0) - Infinity
2.0 / (-0.0) ->-Infinity
关于java - java中浮点值乘以-1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17462450/