非关联浮点加法示例 [英] Example of non associative floating point addition

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

问题描述

我正在写一篇有关浮点数的文章.我将一些简单的测试放入Javascript控制台中进行尝试.

I'm writing an article about floating numbers. I put inside some simple test to try in Javascript console.

我正在寻找一个非交换加法的示例,即:(x + y)+ z!=(z + x)+ y

I'm looking for an example of non commutative addition ie: (x+y)+z!=(z+x)+y

如果您对x y z具有一些有效的值,谢谢.

If you have some values for x y z that works thank you.

推荐答案

没有这样的示例,因为保证可交换,这是IEEE-754定义的浮点加法.相关词汇:

There is no such example, because floating point addition, as defined by IEEE-754, is guaranteed to be commutative. The relevant verbiage:

...每项操作都应像首先产生一个无穷大的精度,无界的中间结果,然后强制该中间结果使其适合目标格式一样.

...Each of the operations shall be performed as if it first produced an intermediate result correct to infinite precision and with unbounded range, and then coerced this intermediate result to fit in the destination's format.

也就是说,加法运算本身是无限精确的.结果中的所有错误都来自丢弃某些精度的需求.由于无限精度(即常规")加法是可交换的,因此这意味着整个操作是可交换的.

That is, the addition itself is performed with infinite precision; all errors in the result come from the need to discard some of that precision. Since infinite-precision (that is, "regular") addition is commutative, that means the operation as a whole is commutative.

您可能会想到的是关联性.浮点加法不是关联的,因为将前两个数字相加后的精度损失通常与将后两个数字相加后的精度损失不相同.最常见的示例称为灾难性取消":(1 + 1e100) + -1e100 = 01 + (1e100 + -1e100) = 1.

What you may be thinking of is associativity. Floating point addition is not associative, because the precision loss following adding the first two numbers will not generally be the same as that from adding the last two numbers. The most common example of this is known as "catastrophic cancellation": (1 + 1e100) + -1e100 = 0, and 1 + (1e100 + -1e100) = 1.

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

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