- Machine epsilon
In
floating point arithmetic , the machine epsilon (also called macheps, machine precision or unit roundoff) is, for a particularfloating point unit , the difference between 1 and the smallest exactly representable number greater than one. It gives an upper bound on the relative error due to rounding of floating point numbers [*cite journal
author = David Goldberg
title = What Every Computer Scientist Should Know About Floating-Point Arithmetic
journal = ACM Computing Surveys (CSUR)
year = 1991
month = March
volume = 23
issue = 1
pages = 5–48
doi = 10.1145/103162.103163
url = http://www.validlab.com/goldberg/paper.pdf
accessdate = 2008-04-28
quote = ] .Example
An
IEEE 754 single precision floating point number has 24 bits of mantissa, including the leading unit digit. The number 1 is represented with an unbiased exponent of 0 and a mantissa of 1.000000000000000000000002 in binary. The next largest representable number has an exponent of 0 and a mantissa of 1.000000000000000000000012. The difference between these numbers is 0.000000000000000000000012, or 2−23. This is the machine epsilon of a floating point unit which uses IEEE single-precision floating point arithmetic. In general, for a floating point type with a base "b" and a mantissa of "p" digits, the epsilon is εmach = "b"1-"p".Other definitions
The machine epsilon is sometimes defined as the smallest positive number which, when added to 1, yields a result other than one. Unlike the definition above, this value depends on the rounding mode. For IEEE single precision in the most common rounding mode (round to even), this value is 2−24 + 2−47, or slightly more than half the value by the definition above. For rounding toward +∞ the value is the smallest representable positive number (2−149, a
denormal ), while for rounding toward -∞ or toward zero it coincides with the earlier definition.Some documents mistakenly use this definition when the other is intended. For example, both the
GNU libc manual [ [http://www.gnu.org/software/libc/manual/html_node/Floating-Point-Parameters.html GNU libc manual, section A.5.3.2] , dated August 5, 2007, retrieved September 28, 2007. ] andMicrosoft Visual C++ documentation [ [http://msdn2.microsoft.com/en-us/library/k15zsh48(VS.80).aspx Run-Time Library Reference: Data Type Constants] , retrieved September 28, 2007. ] define the constant FLT_EPSILON in this way, in conflict with the ISO C standard [WG14 N1124, section 5.2.4.2.2, paragraph 11.] , which mandates the definition at the head of this article, and with their own implementations, which follow the standard.How to determine the macheps
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 be not 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+eps accuracy directly supported by the processor (or coprocessor), not some 1+eps accuracy supported by a specific compiler for a specific operating system, unless it's known to use the best format.
A trivial example is the machine epsilon for integer arithmetic on processors without floating point formats; it is 1, because 1+1=2 is the smallest integer greater than 1.
The following C program does not actually determine the machine epsilon; rather, it determines a number within a factor of two (one
order of magnitude ) of the true machine epsilon, using alinear search .Abridged Output
$ gcc machine_epsilon.c; ./a.out current Epsilon, 1 + current Epsilon 1 2.00000000000000000000 0.5 1.50000000000000000000 ... 0.000244141 1.00024414062500000000 0.00012207 1.00012207031250000000 6.10352E-05 1.00006103515625000000 3.05176E-05 1.00003051757812500000 1.52588E-05 1.00001525878906250000 7.62939E-06 1.00000762939453125000 3.8147E-06 1.00000381469726562500 1.90735E-06 1.00000190734863281250 9.53674E-07 1.00000095367431640625 4.76837E-07 1.00000047683715820312 2.38419E-07 1.00000023841857910156 Calculated Machine epsilon: 1.19209E-07
A similar, Java method:
References
ee also
*
Floating point - general discussion of accuracy issues in floating point arithmeticExternal links
* [http://orion.math.iastate.edu/burkardt/c_src/machar/machar.html MACHAR] , a routine (in C and Fortran) to "dynamically compute machine constants" (ACM algorithm 722)
Wikimedia Foundation. 2010.