gpt4 book ai didi

java - double 时 (x - x) 是否始终为正零,或者有时为负零?

转载 作者:IT老高 更新时间:2023-10-28 13:51:44 25 4
gpt4 key购买 nike

xdouble 时,是否保证 (x - x)+0.0,或有时可能是 -0.0(取决于 x 的符号)?

最佳答案

x - x 可以是 +0.0NaN。在 IEEE 754 算法中没有其他值可以取整(在 Java 中,取整模式为 always round-to-nearest)。两个相同的有限值的减法定义为在这种舍入模式下产生+0.0Mark Dickinson ,在下面的评论中,引用了 IEEE 754 标准的说法,第 6.3 节:

When the sum of two operands with opposite signs (or the difference of two operands with like signs) is exactly zero, the sign of that sum (or difference) shall be +0 in all rounding-direction attributes except roundTowardNegative [...].

这个 page表明特别是 0.0 - 0.0-0.0 - (-0.0) 都是 +0.0

Infinities 和 NaN 在减去它们自己时都会产生 NaN。

关于java - double 时 (x - x) 是否始终为正零,或者有时为负零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24950928/

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