| Machine Epsilon |
Article Index for Machine |
Shopping Epsilon |
Website Links For Machine |
Information AboutMachine Epsilon |
| CATEGORIES ABOUT MACHINE EPSILON | |
| computer arithmetic | |
| articles with example fortran code | |
| articles with example c code | |
|
Because of the inaccuracy of the machine ( it can only remember a certain limited String of digits ) there exists a number called macheps, which is the smallest number that gives a number greater than 1 when added to 1. for example: if in the computer calculates:
but rounds:
then 0.00000000001 is close to the macheps of this machine. The machine epsilon depends on a number of factors regarding Floating Point arithmetic. Every floating point number in a computer is stored as 0s and 1s (typically 32), from which the first bit is the sign bit (0 for positive, 1 for negative) then we have a number ''p'' of bits to describe the base (or Mantissa ), and finally, the rest of the bits defining the exponent. Also, the machine epsilon depend on the rounding rules used in the floating point arithmetic. If the rounding is by chopping, 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 whould mean (50000-73601)/(10000)x10^(500-362) = -2.3601x10^138. In this case, the machine espilon, with chopping, would be 10^(1-5) = 1/10000. HOW TO DETERMINE MACHINE EPSILON IN VARIOUS PROGRAMMING LANGUAGES FORTRAN ! Copyright 2005 Ryan Balfanz ! ! 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 PROGRAM MACHINE_EPSILON IMPLICIT NONE
DO
IF (tmp + machEps == 1.0) EXIT machEps = machEps/2.0 END DO
! Verify our calculation via the intrinsic F95 function EPSILON()
END PROGRAM MACHINE_EPSILON Abridged Output $ f95 machine_epsilon.f95; ./a.out currEp, 1 + currEp 1.00000000000000 2.00000000000000 0.500000000000000 1.50000000000000 0.250000000000000 1.25000000000000 0.125000000000000 1.12500000000000 6.250000000000000E-002 1.06250000000000 3.125000000000000E-002 1.03125000000000 ... ... ... 4.547473508864641E-013 1.00000000000045 2.273736754432321E-013 1.00000000000023 1.136868377216160E-013 1.00000000000011 5.684341886080801E-014 1.00000000000006 2.842170943040401E-014 1.00000000000003 1.421085471520200E-014 1.00000000000001 7.105427357601002E-015 1.00000000000001 3.552713678800501E-015 1.00000000000000 1.776356839400250E-015 1.00000000000000 8.881784197001252E-016 1.00000000000000 4.440892098500626E-016 1.00000000000000 2.220446049250313E-016 1.00000000000000 1.110223024625157E-016 1.00000000000000 Calculated Machine epsilon: 2.220446049250313E-016 EPSILON(x) = 2.220446049250313E-016 C
#include
{ 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( 1.0f + (machEps/2.0f) == 1.0f ) 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.25 1.25000000000000000000 0.125 1.12500000000000000000 0.0625 1.06250000000000000000 ... ... ... 4.44089E-16 1.00000000000000044409 2.22045E-16 1.00000000000000022204 1.11022E-16 1.00000000000000000000 5.55112E-17 1.00000000000000000000 2.77556E-17 1.00000000000000000000 1.38778E-17 1.00000000000000000000 6.93889E-18 1.00000000000000000000 3.46945E-18 1.00000000000000000000 1.73472E-18 1.00000000000000000000 8.67362E-19 1.00000000000000000000 4.33681E-19 1.00000000000000000000 2.1684E-19 1.00000000000000000000 Calculated Machine epsilon: 1.0842E-19 |
|
|