java - java中浮点值乘以-1

标签 java floating-point multiplication

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

相关文章:

python - 浮点表示的模拟

php - 来自 microtime 的圆形 float

c - 如何用 | 转换表达式(或)在 AST 中?

bash - bash中的浮点除法

java - 用于 Java 的 Eurekalog

java - 计算有多少个 "element"出现在双向链表中

java - facebook sdk java查询使用图形API或url/http从actor_id获取名称

java - 安全地将 `float` 转换为 `double` 而不会丢失精度

java - 特定网站链接未在 WebView 中打开

algorithm - 展位倍增算法