Real*4 floating point numbers: The IF statement finds a difference for eps = 0.5966E-07 10% accuracy is only reached for eps = 0.1090E-06 At i,factor,accuracy,sum,dif = 62 1.827 0.9379E-01 1.000 0.1192E-06 ---------------------------------------------------------------- Real*8 floating point numbers: The IF statement finds a difference for eps = 0.1122E-15 10% accuracy is only reached for eps = 0.2031E-15 At i,factor,accuracy,sum,dif = 61 1.809 0.9352E-01 1.000 0.2220E-15 ---------------------------------------------------------------- program accuracy C Copyright, Bernd Berg, FSU Physics, Sep 4, 2000. C PHY 5157, Solution for assignment 3. include 'implicit.8' parameter(n1=1,n2=100) dimension aeps(n1:n2),asum(n1:n2) c print*," " print*,"Real*8 floating point numbers:" one=float(1) two=float(2) ten=float(10) eps=one add=ten factor=float(1)+add c c ---------------------- c i=0 1 i=i+1 ! tame label1. sum=one+eps c print'(" i,eps,sum,factor:",I9,3G16.8)',i,eps,sum,factor if(sum.ne.one) then eps=eps/factor else eps=factor*eps add=add/two factor=one+add end if if(add.gt.(one/float(100))) go to 1 ! Only goto to label1. c c ---------------------- c print*," " print'(" The IF statement finds a difference for eps =",G11.4)', & eps c c The following construction is also to "out-smart" some compilers: print*," " fact0=factor do i=n1,n2 factor=fact0**i aeps(i)=factor*eps asum(i)=one+aeps(i) dif=asum(i)-sqrt(float(1)) acc=abs(aeps(i)-dif)/aeps(i) if(acc.lt.(one/ten)) then print'(" 10% accuracy is only reached for eps =",G11.4)', & aeps(i) print'(" At i,factor,accuracy,sum,dif =",/,I5,4G11.4)', & i,factor,acc,asum(i),dif stop "STOP: Goal reached." end if end do print*,"Accuracy not reached. Enlarge n2!" print'(" i,eps,accuracy,sum,dif:",I4,4G12.5)', & n2,aeps(n2),acc,asum(n2),dif c stop end ---------------------------------------------------------------- implicit real*4 (a-h,o-z) implicit logical (l) ---------------------------------------------------------------- implicit real*8 (a-h,o-z) implicit logical (l)