c From: "COMPUTATIONAL PHYSICS, 2nd Ed" c by RH Landau, MJ Paez, and CC Bordeianu c Copyright Wiley-VCH, 2007. c Electronic Materials copyright: R Landau, Oregon State Univ, 2007; c MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007. c Support by National Science Foundation c c exp-good.f: good algorithm for calculating exponential c related programs: exp-bad.f Program expgood Implicit none c limit for accuracy, max in x, step in x Real*8 element, min, max, step, sum, x Integer n min = 1E-10 max = 10.0 step = 0.1 Open(6, File = 'exp-good.dat', Status = 'Unknown') c execution Do 10 x = 0, max, step sum = 1 element = 1 Do 20 n = 1, 10000 element = element*(-x)/n sum = sum + element if ((abs(element/sum) .lt. min) .AND. (sum .ne. 0)) then Write (6,*) x, sum c N.B. since no "while" in f77, need use "goto" GoTo 10 Endif 20 Continue 10 Continue Close(6) Stop 'data saved in exp-good.dat' End