Machine epsilon
   HOME

TheInfoList



OR:

Machine epsilon or machine precision is an upper bound on the relative approximation error due to
rounding Rounding means replacing a number with an approximate value that has a shorter, simpler, or more explicit representation. For example, replacing $ with $, the fraction 312/937 with 1/3, or the expression with . Rounding is often done to ob ...
in floating point arithmetic. This value characterizes computer arithmetic in the field of
numerical analysis Numerical analysis is the study of algorithms that use numerical approximation (as opposed to symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). It is the study of numerical methods ...
, and by extension in the subject of
computational science Computational science, also known as scientific computing or scientific computation (SC), is a field in mathematics that uses advanced computing capabilities to understand and solve complex problems. It is an area of science that spans many disc ...
. The quantity is also called macheps and it has the symbols Greek
epsilon Epsilon (, ; uppercase , lowercase or lunate ; el, έψιλον) is the fifth letter of the Greek alphabet, corresponding phonetically to a mid front unrounded vowel or . In the system of Greek numerals it also has the value five. It was d ...
\varepsilon. There are two prevailing definitions. In numerical analysis, machine epsilon is dependent on the type of rounding used and is also called unit roundoff, which has the symbol bold Roman u. However, by a less formal, but more widely-used definition, machine epsilon is independent of rounding method and may be equivalent to u or 2u.


Values for standard hardware arithmetics

The following table lists machine epsilon values for standard floating-point formats. Each format uses round-to-nearest.


Formal definition

''Rounding'' is a procedure for choosing the representation of a
real number In mathematics, a real number is a number that can be used to measure a ''continuous'' one-dimensional quantity such as a distance, duration or temperature. Here, ''continuous'' means that values can have arbitrarily small variations. Every ...
in a
floating point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can ...
number system. For a number system and a rounding procedure, machine epsilon is the maximum
relative error The approximation error in a data value is the discrepancy between an exact value and some ''approximation'' to it. This error can be expressed as an absolute error (the numerical amount of the discrepancy) or as a relative error (the absolute er ...
of the chosen rounding procedure. Some background is needed to determine a value from this definition. A floating point number system is characterized by a
radix In a positional numeral system, the radix or base is the number of unique digits, including the digit zero, used to represent numbers. For example, for the decimal/denary system (the most common system in use today) the radix (base number) is ...
which is also called the base, b, and by the precision p, i.e. the number of radix b digits of the
significand The significand (also mantissa or coefficient, sometimes also argument, or ambiguously fraction or characteristic) is part of a number in scientific notation or in floating-point representation, consisting of its significant digits. Depending on ...
(including any leading implicit bit). All the numbers with the same exponent, e, have the spacing, b^. The spacing changes at the numbers that are perfect powers of b; the spacing on the side of larger magnitude is b times larger than the spacing on the side of smaller magnitude. Since machine epsilon is a bound for relative error, it suffices to consider numbers with exponent e=0. It also suffices to consider positive numbers. For the usual round-to-nearest kind of rounding, the absolute rounding error is at most half the spacing, or b^/2. This value is the biggest possible numerator for the relative error. The denominator in the relative error is the number being rounded, which should be as small as possible to make the relative error large. The worst relative error therefore happens when rounding is applied to numbers of the form 1+a where a is between 0 and b^/2. All these numbers round to 1 with relative error a/(1+a). The maximum occurs when a is at the upper end of its range. The 1+a in the denominator is negligible compared to the numerator, so it is left off for expediency, and just b^/2 is taken as machine epsilon. As has been shown here, the relative error is worst for numbers that round to 1, so machine epsilon also is called ''unit roundoff'' meaning roughly "the maximum error that can occur when rounding to the unit value". Thus, the maximum spacing between a normalised floating point number, x, and an adjacent normalised number is 2 \varepsilon , x, .


Arithmetic model

Numerical analysis uses machine epsilon to study the effects of rounding error. The actual errors of machine arithmetic are far too complicated to be studied directly, so instead, the following simple model is used. The IEEE arithmetic standard says all floating-point operations are done as if it were possible to perform the infinite-precision operation, and then, the result is rounded to a floating-point number. Suppose (1) x, y are floating-point numbers, (2) \bullet is an arithmetic operation on floating-point numbers such as addition or multiplication, and (3) \circ is the infinite precision operation. According to the standard, the computer calculates: :x \bullet y = \mbox (x \circ y) By the meaning of machine epsilon, the relative error of the rounding is at most machine epsilon in magnitude, so: :x \bullet y = (x \circ y)(1 + z) where z in absolute magnitude is at most \varepsilon or u. The books by Demmel and Higham in the references can be consulted to see how this model is used to analyze the errors of, say, Gaussian elimination.


Variant definitions

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 formal definition for ''machine epsilon'' is the one used by Prof. James Demmel in lecture scripts, the ''LAPACK'' linear algebra package, numerics research papers and some scientific computing software. Most numerical analysts use the words ''machine epsilon'' and ''unit roundoff'' interchangeably with this meaning. This alternative definition is much more widespread outside academia: ''machine epsilon is the difference between 1 and the next larger floating point number''. By this definition, \varepsilon equals the value of the unit in the last place relative to 1, i.e. b^ (where b is the base of the floating point system and p is the precision) and the unit roundoff is u\, = \varepsilon/2, assuming round-to-nearest mode, and u\, = \varepsilon, assuming round-by-chop. The prevalence of this definition is rooted in its use in the ISO C Standard for constants relating to floating-point types and corresponding constants in other programming languages. It is also widely used in scientific computing software, and in the numerics and computing literature.


How to determine machine epsilon

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. In a strict sense the term ''machine epsilon'' means the 1 + \varepsilon accuracy directly supported by the processor (or coprocessor), not some 1 + \varepsilon accuracy supported by a specific compiler for a specific operating system, unless it's known to use the best format.
IEEE 754 The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point arithmetic established in 1985 by the Institute of Electrical and Electronics Engineers (IEEE). The standard addressed many problems found ...
floating-point formats have the property that, when reinterpreted as a two's complement integer of the same width, they monotonically increase over positive values and monotonically decrease over negative values (see the binary representation of 32 bit floats). They also have the property that 0 < , f(x), < \infty, and , f(x+1) - f(x), \ge , f(x) - f(x-1), (where f(x) is the aforementioned integer reinterpretation of x). In languages that allow type punning and always use IEEE 754-1985, we can exploit this to compute a machine epsilon in constant time. For example, in C: typedef union dbl_64; double machine_eps (double value) Example on Python: def machineEpsilon(func=float): machine_epsilon = func(1) while func(1)+machine_epsilon != func(1): machine_epsilon_last = machine_epsilon machine_epsilon = func(machine_epsilon) / func(2) return machine_epsilon_last 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: return (s.i64 < 0 ? value - s.d64 : s.d64 - value); 64-bit doubles give 2.220446e-16, which is 2−52 as expected.


Approximation

The following simple algorithm can be used to approximate the machine epsilon, to within a factor of two (one
order of magnitude An order of magnitude is an approximation of the logarithm of a value relative to some contextually understood reference value, usually 10, interpreted as the base of the logarithm and the representative of values of magnitude one. Logarithmic di ...
) of its true value, using a linear search. epsilon = 1.0; while (1.0 + 0.5 * epsilon) ≠ 1.0: epsilon = 0.5 * epsilon The machine epsilon, \varepsilon_\text can also simply be calculated as two to the negative power of the number of bits used for the mantissa. \varepsilon_\text\ =\ 2^


Relationship to absolute relative error

If y is the machine representation of a number x then the absolute relative error in the representation is \left, \dfrac \ \leq \varepsilon_\text.


Proof

The following proof is limited to positive numbers and machine representations using round-by-chop. If x is a positive number we want to represent, it will be between a machine number x_ below x and a machine number x_ above x . If x_ = \left( 1.b_b_ \ldots b_ \right)_ \times 2^ , where m is the number of bits used for the magnitude of the
significand The significand (also mantissa or coefficient, sometimes also argument, or ambiguously fraction or characteristic) is part of a number in scientific notation or in floating-point representation, consisting of its significant digits. Depending on ...
, then: \begin x_ &= \left (1.b_b_\ldots b_)_ + (0.00 \ldots 1)_ \right\times 2^\\ &= \left (1.b_b_ \ldots b_)_ + 2^ \right\times 2^\\ &= (1.b_b_ \ldots b_)_ \times 2^ + 2^ \times 2^\\ &= (1.b_b_ \ldots b_)_ \times 2^ + 2^. \end Since the representation of x will be either x_b or x_u , \begin \left, x - y \ &\leq \left, x_ - x_ \\\ &= 2^ \end \begin \left, \frac \ &\leq \frac\\ &\leq \frac\\ &= \frac\\ &= \frac\\ &\leq 2^ = \varepsilon_\text. \end Although this proof is limited to positive numbers and round-by-chop, the same method can be used to prove the inequality in relation to negative numbers and round-to-nearest machine representations.


See also

*
Floating point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can ...
, general discussion of accuracy issues in floating point arithmetic * Unit in the last place (ULP)


Notes and references

* Anderson, E.; ''LAPACK Users' Guide,'' Society for Industrial and Applied Mathematics (SIAM), Philadelphia, PA, third edition, 1999. * Cody, William J.; ''MACHAR: A Soubroutine to Dynamically Determine Machine Parameters,'' ACM Transactions on Mathematical Software, Vol. 14(4), 1988, 303-311. * Besset, Didier H.; ''Object-Oriented Implementation of Numerical Methods,'' Morgan & Kaufmann, San Francisco, CA, 2000. * Demmel, James W., ''Applied Numerical Linear Algebra,'' Society for Industrial and Applied Mathematics (SIAM), Philadelphia, PA, 1997. * Higham, Nicholas J.; ''Accuracy and Stability of Numerical Algorithms,'' Society for Industrial and Applied Mathematics (SIAM), Philadelphia, PA, second edition, 2002. * Press, William H.; Teukolsky, Saul A.; Vetterling, William T.; and Flannery, Brian P.; ''Numerical Recipes in Fortran 77'', 2nd ed., Chap. 20.2, pp. 881–886 * Forsythe, George E.; Malcolm, Michael A.; Moler, Cleve B.; "Computer Methods for Mathematical Computations", Prentice-Hall, , 1977 {{refend


External links


MACHAR
a routine (in C and Fortran) to "dynamically compute machine constants" (ACM algorithm 722)

Implementation of MACHAR in
Component Pascal Component Pascal is a programming language in the tradition of Niklaus Wirth's Pascal, Modula-2, Oberon and Oberon-2. It bears the name of the language Pascal and preserves its heritage, but is incompatible with Pascal. Instead, it is a minor ...
and Oberon based on the Fortran 77 version of MACHAR published in Numerical Recipes (Press et al., 1992). Computer arithmetic Articles with example C code it:Epsilon di macchina