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

查看:207
本文介绍了何时使用DBL_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.

该小量比计算机能够处理的最小值大得多,所以它看起来是一个正确的假设,它的安全比小量使用较小的值?

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 /小量小?

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

推荐答案

DBL_EPSILON的定义是不是这样。它是之后的下一个再presentable数之间的差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 /小量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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