浮点等价? [英] Floating point equivalence?

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

问题描述

我希望能够比较两个双打忽略一个可能的precision损失。有没有一种方法,已经处理这种情况?

I want to be able to compare two doubles disregarding a possible precision loss. Is there a method already that handles this case?

如果不是,是否有一个门槛/准则知道多少是两个双打之间的充分等价?

If not, is there a threshold/guideline to know how much is an adequate equivalence between two doubles?

推荐答案

阈值是完全依赖于问题本身。对于一些问题,你可能会考虑1.001等于1.002和一些问题,你可能需要一个更小的门槛。

The threshold is completely dependent to the problem itself. For some problems, you might consider 1.001 equal to 1.002 and for some problems, you might need a much smaller threshold.

一般己技巧是:

Math.Abs(a - b) < some_epsilon    // `a` is roughly equivalent to `b`

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

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