Machine epsilon
In computer science, the machine epsilon (also called macheps, machine precision or unit roundoff) is, for a particular machine, the smallest number that, when added to 1, gives a number greater than 1. The existence of a machine epsilon is a consequence of finite-precision floating point arithmetic.
Example
If a particular computer calculates as
1 + 0.00000000001 = 1.00000000001 []
but rounds as
1 + 0.000000000001 = 1 []
then the machine epsilon of the computer lies somewhere between and .
The machine epsilon depends on a number of factors regarding floating point arithmetic. Every floating point number in a computer is stored as bits (typically 32 bits), from which the first bit is the sign bit (0 for positive, 1 for negative); then a number p of bits describe the base (or mantissa); and finally, the rest of the bits defining the exponent. The IEEE floating-point standard for example standardizes a method how to represent floating point numbers.
Also, the machine epsilon depends on the rounding rules used in the floating point arithmetic. If the rounding is by truncation, then
ε mach = β^(1-p)
where β is the base (usually 2) and p is the number of bits in the mantissa. If rounding to nearest, then
ε mach = (1/2)β^(1-p)
For example, if we had a computer that, instead of being binary, operated on base 10, and we could have say 10 decimal numbers to represent floating point values, we could set the places to work as follow:
a b c d e f g h
where the number abcde would represent the mantissa (with sign) and fgh the exponent. To allow the sign to be part of the mantissa we need to normalize the result by subtracting the mantissa from 50000 and dividing by 10000, and subtract the exponent from 500. Thus,
7 3 6 0 1 3 6 2
would mean (50000-73601)/(10000)x10^(500-362) = -2.3601x10^138.
In this case, the machine epsilon, with truncation, would be .
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 a linear search.
#include <stdio.h> int main( int argc, char **argv ) { float machEps = 1.0f; printf( "current Epsilon, 1 + current Epsilon\n" ); do { printf( "%G\t%.20f\n", machEps, (1.0f + machEps) ); machEps /= 2.0f; // If next epsilon yields 1, then break, because current // epsilon is the machine epsilon. } while ((float)(1.0 + (machEps/2.0)) != 1.0); printf( "\nCalculated Machine epsilon: %G\n", machEps ); return 0; }
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
See also
- IEEE754 (IEEE floating point standard)
External link
- MACHAR, a routine (in C and Fortran) to "dynamically compute machine constants" (ACM algorithm 722)