Machine epsilon

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

Rounding is a procedure for choosing the representation of a real number in a floating point number system. For a number system and a rounding procedure, machine epsilon is the maximum relative error of the chosen rounding procedure.

By the meaning of machine epsilon, the relative error of the rounding is at most machine epsilon in magnitude, so:

The IEEE standard does not define the terms machine epsilon and unit roundoff, so differing definitions of these terms are in use, which can cause some confusion.

The definition given here for machine epsilon is the one used by Prof. James Demmel in lecture scripts,[4] the LAPACK linear algebra package,[5] numerics research papers[6] and some scientific computing software.[7] Most numerical analysts use the words machine epsilon and unit roundoff interchangeably with this meaning.

Machine epsilon is defined as the difference between 1 and the next larger floating point number.

Where standard libraries do not provide precomputed values (as <float.h> does with FLT_EPSILON, DBL_EPSILON and LDBL_EPSILON for C and <limits> does with std::numeric_limits<T>::epsilon() in C++), the best way to determine machine epsilon is to refer to the table, above, and use the appropriate power formula. Computing machine epsilon is often given as a textbook exercise. The following examples compute machine epsilon in the sense of the spacing of the floating point numbers at 1 rather than in the sense of the unit roundoff.

Note that results depend on the particular floating-point format used, such as float, double, long double, or similar as supported by the programming language, the compiler, and the runtime library for the actual platform.

Some formats supported by the processor might not be supported by the chosen compiler and operating system. Other formats might be emulated by the runtime library, including arbitrary-precision arithmetic available in some languages and libraries.

This will give a result of the same sign as value. If a positive result is always desired, the return statement of machine_eps can be replaced with:

The following simple algorithm can be used to approximate[clarification needed] the machine epsilon, to within a factor of two (one order of magnitude) of its true value, using a linear search.

epsilon = 1.0; while (1.0 + 0.5 * epsilon) ≠ 1.0: epsilon = 0.5 * epsilon