浮点数添加的关联属性 [英] Associative Property on floating point number additions

查看:65
本文介绍了浮点数添加的关联属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让x,y和z为浮点数.那么(x + y)+ z =/= x +(y + z)是真的吗?有人可以给我一个例子吗?我希望x,y和z是浮点数(IEEE表示),而不仅仅是任何实数.

Let x, y, and z be floating point numbers. Then is it true that (x+y)+z =/= x+(y+z)? Can someone give me an example? I want x,y, and z be floating point numbers (IEEE representation), not just any real numbers.

推荐答案

正如您所说的那样,它通常不是正确的.存在x,y和z,使得(x+y)+z = x+(y+z).但是您可能想问(x+y)+z = x+(y+z)是否总是正确的.并非总是如此.

As you phrased the question, it is not generally true. There exist x, y, and z such that (x+y)+z = x+(y+z). But you likely intended to ask whether or not it is always true that (x+y)+z = x+(y+z). It is not always true.

一个明显的反例是(2 64 + -2 64 )+ 1和2 64 +(-2 64 + 1).使用64位二进制IEEE-754算法,前者为0 +1 = 1,后者为2 64 + -2 64 = 0.因为-2 64 的大小太大,所以1丢失了,总和没有足够的精度来包含1.

An obvious counterexample is (264 + -264) + 1 and 264 + (-264 + 1). With 64-bit binary IEEE-754 arithmetic, the former is 0 + 1 = 1, and the latter is 264 + -264 = 0. In the latter, the 1 was lost because the magnitude of -264 is so great the sum did not have enough precision to include the 1.

还有更微妙的情况,其中一个数字的一​​部分丢失了.

There are more subtle cases, where just a part of one number is lost.

这篇关于浮点数添加的关联属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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