What is EPS? Are there any function in C++ for EPS? How do I output a value with eps 1e-12?

Printable View

- 08-16-2013Tamim Ad DariWhat is EPS?
__What is EPS? Are there any function in C++ for EPS? How do I output a value with eps 1e-12?__ - 08-16-2013grumpy
EPS is a set of three letters. It could mean anything.

One relatively common meaning is that it is shorthand for "machine epsilon", which is a machine-dependent floating point value that provides an upper bound on relative error due to rounding in floating point arithmetic. Mathematically, for each floating point type, it is equivalent to the difference between 1.0 and the smallest representable value that is greater than 1.0.

In C, machine epsilon is specified in the standard header <float.h>, with the names FLT_EPSILON, DBL_EPSILON, and LDBL_EPSILON. Those three macros give the machine epsilon for the float, double, and long double types, respectively.

In C++, similar macros are available in the standard header <cfloat> (as C's <float.h> is deprecated in C++). The preferred (by some) way in C++ is to use std::numeric_limits<floating_point_type>::epsilon( ) - specified in the standard header <limits>. For example, machine epsilon for the float type is std::numeric_limits<float>::epsilon(). Yes, epsilon() is a member function of std::numeric_limits<float>, so the brackets are required.

There is no requirement that the machine epsilon have a value of 1e-12. The actual value depends on the floating point type.

If you want to print out a value that small to an output stream (like std::out) look up the setw() and setprecision() steam manipulators (both are specified in standard header <iomanip>).