The definition and calculation of a numerical value that is often useful in a numerical calculation

Source: Internet
Author: User

In MATLAB, EPS is used directly, and the default is for double-precision types.


So in Microsoft's MSDN:

Numeric_limits::epsilon

The function returns the difference between 1 and the smallest value greater than 1 that's representable for the data typ E.

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

code example:

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 Floa T 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" : "         << numeric_limits<long Double>::epsilon ()         << Endl;}

The output is:

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 a long double objects is: 2.22045e-016


There is a table in the wiki:


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:

Machine Machine
IEEE 754-2008 Common name C + + data type Base PrecisionEpsilon[a] Epsilon[b]
Binary16 Half Precision Short 2 One bit is implicit 2?11 = 4.88e-04 2?10 = 9.77e-04
Binary32 Single precision Float 2 (one bit is implicit) 2?24 = 5.96e-08 2?23 = 1.19e-07
Binary64 Double precision Double 2 (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 5x10?7 10?6
Decimal64 Double Precision Decimal _decimal64[2] 10 16 5x10?16 10?15
decimal128 Quad (ruple) Precision Decimal _decimal128[2] 10 34 5x10?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


If you use extension software tools such as GMP/MPIR/MPFR to increase the accuracy of the actual participation in the calculation, use Pavel C + + wrapper mpfrc++ (it's strange that his profile only involves technology-related information is also blocked), combined with eigen C + + template The library is my favorite.

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


In Linux, the source code for such libraries on MacOS is usually no problem, and it's a little cumbersome under Windows. Here's a modified package that can be compiled directly under Visual Studio into a dynamic and static-link library of project files, Mpir,mpfr,mpc,gmpy is included. I set the download required resource score to 10, in fact, after the normal comment according to the rule this resource will automatically return and will be extra points. So there is no psychological pressure when downloading. Can't accept, can go to code.google.com the above link to download. There is no problem.


The definition and calculation of numeric values that are often useful in a numeric calculation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.