一个数值计算中通常非常实用的数值的定义和计算

matlab中直接用eps,默认是针对double双精度类型的.


微软的msdn中是这么提的:

numeric_limits::epsilon

The function returns the difference between 1 and the smallest value greater than 1 that is representable for the data type.

The difference between 1 and the smallest value greater than 1 that is representable for the data type.

代码样例:

// numeric_limits_epsilon.cpp
// compile with: /EHsc
#include <iostream>
#include <limits>

using namespace std;

int main( )
{
   cout << "The difference between 1 and the smallest "
        << "value greater than 1
 for float objects is: " 
        << numeric_limits<float>::epsilon( ) 
        << endl;
   cout << "The difference between 1 and the smallest "
        << "value greater than 1
 for double objects is: " 
        << numeric_limits<double>::epsilon( ) 
        << endl;
   cout << "The difference between 1 and the smallest "
        << "value greater than 1
 for long double objects is: " 
        << numeric_limits<long double>::epsilon( ) 
        << endl;
}

输出结果是:

The difference between 1 and the smallest value greater than 1
for float objects is: 1.19209e-007
The difference between 1 and the smallest value greater than 1
for double objects is: 2.22045e-016
The difference between 1 and the smallest value greater than 1
for long double objects is: 2.22045e-016


维基中有这样一个表格:


Values for standard hardware floating point arithmetics

http://eigen.tuxfamily.org/index.php?title=Main_Page

The following values of machine epsilon apply to standard floating point formats:

IEEE 754 - 2008 Common name C++ data type Base b Precision p Machine epsilon[a]b^{-(p-1)}/2 Machine epsilon[b]b^{-(p-1)}
binary16 half precision short 2 11 (one bit is implicit) 2−11 = 4.88e-04 2−10 = 9.77e-04
binary32 single precision float 2 24 (one bit is implicit) 2−24 = 5.96e-08 2−23 = 1.19e-07
binary64 double precision double 2 53 (one bit is implicit) 2−53 = 1.11e-16 2−52 = 2.22e-16
binary80 extended precision _float80[1] 2 64 2−64 = 5.42e-20 2−63 = 1.08e-19
binary128 quad(ruple) precision _float128[1] 2 113 (one bit is implicit) 2−113 = 9.63e-35 2−112 = 1.93e-34
decimal32 single precision decimal _Decimal32[2] 10 7 5 × 10−7 10−6
decimal64 double precision decimal _Decimal64[2] 10 16 5 × 10−16 10−15
decimal128 quad(ruple) precision decimal _Decimal128[2] 10 34 5 × 10−34 10−33

a according to Prof. Demmel,LAPACK,Scilabb according to Prof. Higham; ISO C standard;C, C++ and Python language constants; Mathematica, MATLAB and Octave; various textbooks - see below for the latter definition


假设使用了GMP/MPIR/MPFR之类的扩展软件工具来提高实际參与计算的精度, 用Pavel的C++ wrapper mpfrC++(非常奇怪他的个人主页仅仅涉及技术相关信息也被屏蔽了), 结合Eigen C++ template library是我的最爱.

https://code.google.com/p/gmpy/downloads/detail?name=full-src-mpir-mpfr-mpc-gmpy2-2.0.2.zip&can=2&q=


在Linux, MacOS上这类库的源码直接编译通常没有问题, 在windows下略微有些麻烦. 这里有一个改动后的,能够在visual studio以下直接编译成动态和静态链接库的项目文件的包,mpir,mpfr,mpc,gmpy都包含了. 我把下载所需资源分数设置为10,实际上,正常评论之后依据规则这个资源分都会自己主动返还并且会额外加分的. 所下面载的时候别有心理压力. 实在接受不了,能够到code.google.com的上面的链接中去下载. 没有不论什么问题.


原文地址:https://www.cnblogs.com/mfrbuaa/p/5199905.html