何时使用DBL_EPSILON / epsilon [英] When to use DBL_EPSILON/epsilon

查看:801
本文介绍了何时使用DBL_EPSILON / epsilon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DBL_EPSILON / std :: numeric_limits :: epsilon会给我最小的值,在添加时会有所不同。

The DBL_EPSILON/std::numeric_limits::epsilon will give me the smallest value that will make a difference when adding with one.

我无法理解如何将这些知识应用到有用的东西中。

I'm having trouble understanding how to apply this knowledge into something useful.

epsilon比计算机可以处理的最小值大得多,因此看起来像一个正确的假设,使用比epsilon更小的值?

The epsilon is much larger than the smallest value the computer can handle, so It would seem like a correct assumption that its safe to use smaller values than epsilon?

如果我使用的值之间的比值小于1 / epsilon?

Should the ratio between the values I'm working with be smaller than 1/epsilon ?

推荐答案

DBL_EPSILON的定义不是这样。它是1和1之间的下一个可表示数字之间的差异(您的定义假定舍入模式设置为向0或向负无穷大,这不总是真的)。​​

The definition of DBL_EPSILON isn't that. It is the difference between the next representable number after 1 and 1 (your definition assumes that the rounding mode is set to "toward 0" or "toward minus infinity", that's not always true).

如果你对数值分析有足够的了解,这是有用的。但我恐怕这个地方不是最好的了解。作为一个例子,你可以使用它来构建一个比较函数,它会告诉两个浮点数是否近似等于这样

It's something useful if you know enough about numerical analysis. But I fear this place is not the best one to learn about that. As an example, you could use it in building a comparison function which would tell if two floating point numbers are approximatively equal like this

bool approximatively_equal(double x, double y, int ulp)
{
   return fabs(x-y) <= ulp*DBL_EPSILON*max(fabs(x), fabs(y));
}

(但不知道如何确定ulp,如果中间结果是正规的,这个函数可能有问题; fp计算是复杂的,使得鲁棒)

(but without knowing how to determine ulp, you'll be lost; and this function has probably problems if intermediate results are denormals; fp computation is complicated to make robust)

这篇关于何时使用DBL_EPSILON / epsilon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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