一个数值计算中通常很有用的数值的定义和计算
2015-06-11 14:38
281 查看
matlab中直接用eps,默认是针对double双精度类型的.
在微软的msdn中是这么提的:
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.
代码例子:
输出结果是:
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
在维基中有这样一个表格:
The following values of machine epsilon apply to standard floating point formats:
[b]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的上面的链接中去下载. 没有任何问题.
在微软的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_PageThe 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 |
---|---|---|---|---|---|---|
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 |
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的上面的链接中去下载. 没有任何问题.
相关文章推荐
- 在较低版本上面使用Material Design风格
- selenium 中定位及打开浏览器操作代码
- Ubuntu Server 下的网络配置
- UIImageview 通过 UITapGestureRecognizer添加点击事件
- GRE机考阅读流程
- FlexiGrid使用手册
- Make.am中生成.la动态库的同时要链接.a静态库的问题
- web.xml被文件加载过程,各节点加载顺序总结
- oracle递归数结构数据
- Connection closed by foreign host.
- Linux系统编程——线程私有数据
- linux及安全结课——总结
- nodejs 安装
- iOS时间类型转换和各种数据类型进行转换
- Qt之加密算法[转]
- StringUtils.isEmpty和StringUtils.isBlank用法
- autotools使用总结
- 适配的问题
- 【bzoj_1005】[HNOI2008]明明的烦恼
- 页缓存算法(页面置换算法)