一个数值计算中通常很有用的数值的定义和计算

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

在微软的msdn中是这么提的:

numeric_limits::epsilonThe 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-007The difference between 1 and the smallest value greater than 1for double objects is: 2.22045e-016The difference between 1 and the smallest value greater than 1for long double objects is: 2.22045e-016

在维基中有这样一个表格:

Values for standard hardware floating point arithmetics

?title=Main_Page

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

IEEE 754 – 2008Common nameC++ data typeBase Precision Machine epsilonMachine epsilon

binary16half precisionshort211 (one bit is implicit)211 = 4.88e-04210 = 9.77e-04

binary32single precisionfloat224 (one bit is implicit)224 = 5.96e-08223 = 1.19e-07

binary64double precisiondouble253 (one bit is implicit)253 = 1.11e-16252 = 2.22e-16

binary80extended precision_float80264264 = 5.42e-20263 = 1.08e-19

binary128quad(ruple) precision_float1282113 (one bit is implicit)2113 = 9.63e-352112 = 1.93e-34

decimal32single precision decimal_Decimal321075 × 107106

decimal64double precision decimal_Decimal6410165 × 10161015

decimal128quad(ruple) precision decimal_Decimal12810345 × 10341033

according to Prof. Demmel,LAPACK,Scilab 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的上面的链接中去下载. 没有任何问题.

,明天的希望,让我们忘了今天的痛苦

一个数值计算中通常很有用的数值的定义和计算

相关文章:

你感兴趣的文章:

标签云: