PROGRAM LIMITS C C This code will determine the machine precision for the machine on which it C runs. It is based on pseudocode from Computational Physics: Problem C Solving with Python, Third Edition} (2015) of Landau, Paez, and Bordeiana C on Page 50. C C At the Unix prompt, use the command: C gfortran -o limits.exe limits.f (Linux Workstations) C to create the executable version of this code. C C Below we define some of the variables that will be used in this code: C I: An integer counter variable for the current iteration. C NITER: The maximum number of iterations allowed. C SEPS: The machine error value for single-precision numbers. C SONE: The current value of 1. + SEPS. C DEPS: The machine error value for double-precision numbers. C DONE: The current value of 1. + DEPS. C ASK: A character string of one character containing either 'y' (yes) C or 'n' (no). C INTEGER I, NITER REAL SEPS, SONE DOUBLE PRECISION DEPS, DONE CHARACTER ASK C C Set an initial guess for how many iterations this will take. C DATA NITER / 200 / C C Determine the machine precision. Ask the user to continue every 100th C iteration. Define initial values for SEPS and DEPS. C SEPS = 1.0 DEPS = 1.0D0 C C Single precision calculation. C PRINT *, 'In the tabel below:' PRINT *, ' ITER: The iteration number.' PRINT *, ' ONE: The value for the REAL variable ONE.' PRINT *, ' EPS: The difference of ONE and the integer 1.' PRINT *, 'When the value printed for ONE is exactly 1, the' PRINT *, 'value for EPS will be the machine precision for a' PRINT *, 'single precision variable.' PRINT *, ' ' PRINT *, ' ITER ONE EPS' DO 100 I = 1, NITER SEPS = SEPS / 2.0 SONE = 1.0 + SEPS WRITE (*,50) I, SONE, SEPS 50 FORMAT(I4, 2X, F15.12, 2X, 1PE14.7) IF (MOD(I, 100) .EQ. 0) THEN PRINT *, 'Continue with the single precision ', 1 'calculations (y/n)? [y]' READ (*, '(A)') ASK IF ((ASK .EQ. 'N') .OR. (ASK .EQ. 'n')) GOTO 200 ENDIF 100 CONTINUE C C Double precision calculation. C 200 PRINT *, ' ' PRINT *, 'In the tabel below:' PRINT *, ' ITER: The iteration number.' PRINT *, ' ONE: The value for the REAL*8 variable ONE.' PRINT *, ' EPS: The difference of ONE and the integer 1.' PRINT *, 'When the value printed for ONE is exactly 1, the' PRINT *, 'value for EPS will be the machine precision for a' PRINT *, 'double precision variable.' PRINT *, ' ' PRINT *, ' ITER ONE EPS' DO 300 I = 1, NITER DEPS = DEPS / 2.0D0 DONE = 1.0D0 + DEPS WRITE (*,250) I, DONE, DEPS 250 FORMAT(I4, 2X, F23.20, 2X, 1PE23.15) IF (MOD(I, 100) .EQ. 0) THEN PRINT *, 'Continue with the double precision ', 1 'calculations (y/n)? [y]' READ (*, '(A)') ASK IF ((ASK .EQ. 'N') .OR. (ASK .EQ. 'n')) STOP ENDIF 300 CONTINUE C STOP END