操作顺序以最大程度地提高精度 [英] Order of operations to maximize precision

查看:72
本文介绍了操作顺序以最大程度地提高精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用浮点数进行这些操作:

I'm using floats for these operations:

这两个中哪个更精确?

  • (a * b)/c

  • (a/c)* b

这到底有关系还是取决于情况?如果是这样,在什么情况下我应该选择哪个?

Does it matter at all or does it depend on the situation? If so, which should I choose in what cases?

推荐答案

真的,如果您不使用double,那么您会被误导,而且也不关心精度.

Really, if you don't use double then you are misguided, and you don't care about precision.

否则,如果第一个结果稍低于下一个较高的2的幂,则将得到最佳的误差范围.例如,计算(pi * e)/sqrt(2),您可以通过计算(e/sqrt(2))* pi获得最佳误差范围,因为e/sqrt(2)≈1.922接近于2.结果close到下一个较高的二的幂具有较低的相对误差.

Otherwise, you get the best error bounds if the first result is slightly lower than the next higher power of two. For example, calculating (pi * e) / sqrt (2), you get the best error bounds by calculating (e / sqrt (2)) * pi, because e / sqrt (2) ≈ 1.922 is close below 2. Results close to the next higher power of two have a lower relative error.

对于大量项目的加减法,最好首先减去大小相等且符号相反的项目(如果y/2≤x≤2y则精确计算x-y),否则将给出最小的数字相结合可能的结果.

For addition and subtraction of a large number of items, it's best to first subtract items of equal magnitude and opposite sign (x - y is calculated exactly if y/2 ≤ x ≤ 2y), and otherwise combining numbers giving the smallest possible results.

这篇关于操作顺序以最大程度地提高精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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