12 real(r8),
intent(in) :: c0, c1, c2, c3
14 real(r8),
intent(out) :: x1, x2, x3
15 integer(itm_i4),
intent(out) :: ifail
18 real(r8) :: aa, bb, cc, det
20 real(r8) :: a0, a1, a2
23 real(r8) :: angle, dum
31 if (abs(c3) / (abs(c1) + abs(c2) + abs(c3)) < 1.e-9_r8)
then
35 det = bb**2 - 4._r8 * aa * cc
37 x1 =
root(aa, bb, cc, det, 1._r8)
38 if (abs(x1) > 1._r8 + tol)
then
39 x1 =
root(aa, bb, cc, det, -1._r8)
46 pi = 2._r8 * asin(1._r8)
50 p = -(a2**2) / 3._r8 + a1
51 q = 2._r8 / 27._r8 * (a2**3) - a2 * a1 / 3._r8 + a0
52 det = (
p / 3._r8)**3 + (q / 2._r8)**2
54 u = sign(1._r8, -q / 2._r8 + sqrt(det)) * abs(-q / 2._r8 &
55 + sqrt(det))**(1._r8 / 3._r8)
56 v = sign(1._r8, -q / 2._r8 - sqrt(det)) * abs(-q / 2._r8 &
57 - sqrt(det))**(1._r8 / 3._r8)
58 x1 = u + v - a2 / 3._r8
59 if (abs(x1) >= 1._r8 + tol) ifail = 1
62 angle = sign(1._r8,
p) * acos((q / 2._r8) / sqrt(abs(
p) &
64 x1 = -2._r8 * sqrt(abs(
p) / 3._r8) * cos(angle / 3._r8) &
66 x2 = -2._r8 * sqrt(abs(
p) / 3._r8) * cos(2._r8 * pi &
67 / 3._r8 - angle / 3._r8) - a2 / 3._r8
68 x3 = -2._r8 * sqrt(abs(
p) / 3._r8) * cos(2._r8 * pi &
69 / 3._r8 + angle / 3._r8) - a2 / 3._r8
71 if (abs(x1) > abs(x2))
then
76 if (abs(x2) > abs(x3))
then
81 if (abs(x1) > abs(x2))
then
87 if (abs(x1) > 1._r8 + tol) ifail = 1
subroutine solve_cubic(c0, c1, c2, c3, x1, x2, x3, ifail)
real(r8) function, public root(a, b, c, d, sgn)
real(r8) function p(a, x, xr, xs, yr, ys, psi, psir, F_dia)