      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
