Machine Epsilon

Frequently,  "Hello World" is the first program tried on any new computer,  or in any new computer language.

A close second, if the work involves Numerical Methods, might be a program for Machine Epsilon, which gives an estimate of the accuracy of the floating point arithmetic.

The Fortran program below is after page 14 in Forsythe, Malcolm, and Moler,  Computer Methods for Mathematical Computations, Prentice-Hall, 1977.

     CALL ONE

     CALL TWO

      CALL FOUR

      STOP

      END

 

      SUBROUTINE ONE

     REAL*4 EPS, E2

      EPS=1.0

 10    E2=EPS/2.

     IF ( 1.0+E2 .EQ. 1.0 ) GOTO 20

     EPS=E2

     GOTO 10

 20   WRITE (6,100) EPS

 100  FORMAT (' Machine epsilon Single Precision is ',1PE9.2)

      RETURN

     END

 

     SUBROUTINE TWO

      REAL*8 EPS, E2

      EPS=1.0

 10   E2=EPS/2.

      IF ( 1.0+E2 .EQ. 1.0 ) GOTO 20

      EPS=E2

  GOTO 10

 20      WRITE (6,100) EPS

 100   FORMAT (' Machine epsilon Double Precision is ',1PE9.2)

   RETURN

   END

 

   SUBROUTINE FOUR

   REAL*16 EPS, E2

   EPS=1.0

 10   E2=EPS/2.

   IF ( 1.0+E2 .EQ. 1.0 ) GOTO 20

   EPS=E2

   GOTO 10

 20   WRITE (6,100) EPS

 100  FORMAT (' Machine epsilon Quad   Precision is ',1PE9.2)

   RETURN

   END

  Machine epsilon Single Precision is  1.08E-19

 Machine epsilon Double Precision is  1.08E-19

 Machine epsilon Quad   Precision is  1.93E-34

The above results are from the GNU  MinGW Fortran compiler on a 64-bit Windows 11 machine.  

In this implementation, Single and Double Precision have the same epsilon.  It always pays to check!

I remember, long ago, having a wide smile when I gained access to a CDC 6400 computer with its 60 bit word-length and the associated machine epsilon.  Now such machines are the norm.