Machine Epsilon Article Index for
Machine
Shopping
Epsilon
Website Links For
Machine
 

Information About

Machine Epsilon





EXAMPLE

If a particular computer calculates 1 + 10^{-10} as

1 + 0.00000000001 = 1.00000000001 + .1 imes 10^{-10} = 1.00000000001

but rounds 1 + 10^{-11} as

1 + 0.000000000001 = 1 +.1 imes 10^{-11}= 1

then the machine epsilon of the computer lies somewhere between 10^{-10} and 10^{-11}.

The machine epsilon depends on a number of factors regarding Floating Point arithmetic. Every floating point number in a computer is stored as Bit s (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 10^{1-5} = 1/10000.


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 .

  • --- Copyright 2006 Edgar A. Duenez-Guzman


  • This program is free software; you can redistribute it and/or modify

  • it under the terms of the GNU General Public License as published by

  • the Free Software Foundation; either version 2 of the License, or

  • (at your option) any later version.


  • This program is distributed in the hope that it will be useful,

  • but WITHOUT ANY WARRANTY; without even the implied warranty of

  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

  • GNU General Public License for more details.


  • You should have received a copy of the GNU General Public License

  • along with this program; if not, write to the Free Software

  • Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

  • / -->

  • #include


  • ---argv )

  • {

float machEps = 1.0f;

printf( "current Epsilon, 1 + current Epsilon
" );
while(1)
{
printf( "%G %.20f
", machEps, (1.0f + machEps) );
machEps /= 2.0f;
// If next epsilon yields 1, then break, because current
// epsilon is the machine epsilon.
if( (float)(1.0 + (machEps/2.0)) == 1.0 )
break;
}

printf( "
Calculated Machine epsilon: %G
", 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)