gpt4 book ai didi

java - java中浮点值乘以-1

转载 作者:行者123 更新时间:2023-12-01 17:22:36 25 4
gpt4 key购买 nike

为什么当 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com