机precision [英] machine precision

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

问题描述

我不知道是否有类似的EPS重新present机precision的价值在C ++?我可以用它为最小的正数双可以重新present?是有可能使用1.0 / EPS为最大的正数,一个双可以重新present?我在哪里可以找到在C ++和C标准库?

I wonder if there is something like eps to represent the value of machine precision in C++? Can I use it as the smallest positive number that a double can represent? Is it possible to use 1.0/eps as the max positive number that a double can represent? Where can I find eps in both C++ and C standard libraries?

感谢和问候!

更新:

有关我的目的,我想计算重量的距离倒数的是这样反距离加权插值(http://en.wikipedia.org/wiki/Inverse_distance_weighting)。

For my purpose, I would like to compute a weight as reciprocal of a distance for something like inverse distance weighting interpolation (http://en.wikipedia.org/wiki/Inverse_distance_weighting).

double wgt = 0, wgt_tmp, result = 0;
for (int i = 0; i < num; i++)
{
   wgt_tmp = 1.0/dist[i];
   wgt += wgt_tmp;
   result += wgt_tmp * values[i];
}
results /= wgt;

但是距离可以是0,我需要做的重量适合计算。如果只有一个距离DIST [i]为0时,我想其相应的值的值由[i]是占主导地位。如果有几个距离是0,我想有自己的价值观,以同样的结果作出贡献。任何想法如何实现它?

However the distance can be 0 and I need to make the weight suitable for computation. If there is only one distance dist[i] is 0, I would like its corresponding value values[i] to be dominant. If there are several distances are 0, I would like to have their values to contribute equally to the result. Any idea how to implement it?

推荐答案

这完全取决于你从数字的愿望precision,在双最大值是非常大的,但是从巨大的舍入误差受到影响。如果需要的1E-3 precision例如至少需要10比特的浮点后,这意味着你不应该有比在尾数减去10位的数目更大的任何指数,在双的情况下即52 - 10 = 42,留下一个最高约4e12和大约2.5E-13的对应最小

This depends entirely on the precision you desire from your numbers, the maximum value in a double is very large, but suffers from tremendous rounding errors. If you need a precision of 1e-3 for instance you need at least 10 bits after the floating point, meaning you should not have any exponent greater than the number of bits in the mantissa minus 10, in the case of a double, that is 52 - 10 = 42, leaving you with a maximum of about 4e12 and a corresponding minimum of about 2.5e-13.

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

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