      subroutine ecuber(t,f,fp,ta,fa,fpa,tlower,tupper)
c
c --- arguments
c
      real t,f,fp,ta,fa,fpa,tlower,tupper
c
c --- variables locales
c
      real sign,den,anum
      real z1,b,discri
c
c           Using f and fp at t and ta, computes new t by cubic formula
c           safeguarded inside [tlower,tupper].
c
      z1=fp+fpa-3.0*(fa-f)/(ta-t)
      b=z1+fp
c
c              first compute the discriminant (without overflow)
c
      if (abs(z1).le.1.) then
          discri=z1*z1-fp*fpa
        else
          discri=fp/z1
          discri=discri*fpa
          discri=z1-discri
          if (z1.ge.0.0 .and. discri.ge.0.0) then
              discri=sqrt(z1)*sqrt(discri)
              go to 120
          endif
          if (z1.le.0.0 .and. discri.le.0.0) then
              discri=sqrt(-z1)*sqrt(-discri)
              go to 120
          endif
          discri=-1.0
      endif
      if (discri.lt.0.0) then
          if (fp.lt.0.) t=tupper
          if (fp.ge.0.) t=tlower
          go to 900
      endif
c
c  discriminant nonnegative, compute solution (without overflow)
c
      discri=sqrt(discri)
  120 if (t-ta.lt.0.) discri=-discri
      sign=(t-ta)/abs(t-ta)
      if (b*sign.gt.0.) then
          t=t+fp*(ta-t)/(b+discri)
        else
          den=z1+b+fpa
          anum=b-discri
          if (abs((t-ta)*anum).lt.(tupper-tlower)*abs(den)) then
              t=t+anum*(ta-t)/den
            else
              t=tupper
          endif
      endif
  900 t=max(t,tlower)
      t=min(t,tupper)
      return
      end
c
c-----------------------------------------------------------------------
c

