1
subroutine fcube(t,f,fp,ta,fa,fpa,tlower,tupper)
3
implicit double precision (a-h,o-z)
5
c Using f and fp at t and ta, computes new t by cubic formula
6
c safeguarded inside [tlower,tupper].
8
z1=fp+fpa-3.d0*(fa-f)/(ta-t)
11
c first compute the discriminant (without overflow)
13
if (dabs(z1).le.1.d0) then
19
if (z1.ge.0.d0 .and. discri.ge.0.d0) then
20
discri=dsqrt(z1)*dsqrt(discri)
23
if (z1.le.0.d0 .and. discri.le.0.d0) then
24
discri=dsqrt(-z1)*dsqrt(-discri)
29
if (discri.lt.0.d0) then
30
if (fp.lt.0.d0) t=tupper
31
if (fp.ge.0.d0) t=tlower
35
c discriminant nonnegative, stable solution formula
38
200 if (t-ta.lt.0.d0) discri=-discri
39
sign=(t-ta)/dabs(t-ta)
40
if (b*sign.gt.0.) then
45
anum=(ta-t)*(b-discri)
48
c now compute the ratio (without overflow)
50
if (dabs(den).ge.1.d0) then
53
if (dabs(anum).lt.(tupper-tlower)*dabs(den)) then
56
if (fp.lt.0.d0) t=tupper
57
if (fp.ge.0.d0) t=tlower