      subroutine smith(a, b, c, d, e, f)
      implicit none
      double precision a, b
      double precision c, d
      double precision e, f
      double precision den, r
      if (abs(c) .ge. abs(d)) then
        r = d / c
        den = c + r*d
        e = (a + b*r) / den
        f = (b - a*r) / den
      else
        r = c / d
        den = d + r*c
        e = (a*r + b) / den
        f = (b*r - a) / den
      endif
      end
      
      subroutine compare(a, b, c, d, er, ei)
      implicit none
      double precision a, b
      double precision c, d
      double precision er, ei
      complex*16 ca, cb, cc
      double precision e, f
      integer ierr
      call smith(a, b, c, d, e, f)
      write(6,'(A15,E25.10E3,A4,E25.10E3)') "Smith:", e, " +I*", f
      end

      program testcomplexdiv
      implicit none
      call compare(1.d307, 1.d-307, 1.d205, 1.d-205, 1.d102, -1.d-308)
      end

