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\n for float objects is: " << numeric_limits<float>::epsilon( ) << endl; cout << "The difference between 1 and the smallest " << "value greater than 1\n for double objects is: " << numeric_limits<double>::epsilon( ) << endl; cout << "The difference between 1 and the smallest " << "value greater than 1\n 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 | Precision | Machine epsilon[a] | Machine epsilon[b] |
---|---|---|---|---|---|---|
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的上面的链接中去下载. 没有任何问题.