可能有``一个&lt; b而不是(a - b <0)`与浮游物 [英] Possible to have ``a &lt; b and not(a - b &lt; 0)`` with floats

查看:90
本文介绍了可能有``一个&lt; b而不是(a - b <0)`与浮游物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



a< b而不是(a - b <0)



由于浮点错误,
是否有示例?

解决方案

它取决于浮点格式,特别是它是否具有渐变下溢。 IEEE 754二进制浮点数。这意味着两个不同的花车之间的差距总是非零的,即使在极端情况下它只能用一个重要的比特来表示。

最小可能的绝对差值在两个不同的花车之间有等号(或零号之一),零指数和相差1的有效数字。在这种情况下,从较小的数字中减去较大的数字将得到最小的数字负号,零指数和有效数字1.该数字比较小于零。

还有其他的计算可以下溢为零。例如,在正常舍入模式下,将最小正数除以大于或等于2的数字,结果为零。

Is

a < b and not(a - b < 0)

possible for floating points due to floating point round of error? Is there an example?

解决方案

It depends on the floating point format, and specifically whether it has gradual underflow. IEEE 754 binary floating point does. That means the gap between two distinct floats is always non-zero, even if it can only be represented with one significant bit in the extreme case.

The smallest possible absolute difference between two distinct floats comes with equal sign (or one of the numbers zero), zero exponent, and significands that differ by 1. In that case, subtracting the larger from the smaller would result in the smallest magnitude negative number, with negative sign, zero exponent, and significand 1. That number compares less than zero.

There are other calculations that do underflow to zero. For example, dividing the smallest positive number by a number greater than or equal to two results in zero in the normal rounding mode.

这篇关于可能有``一个&lt; b而不是(a - b <0)`与浮游物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆