90 der[13] = coeff * (alg[2] * x[16] - alg[1] * x[20]);
91 der[14] = ((alg[2] * x[17] - x[21] * alg[1]) * coeff) / 2;
92 der[15] = (coeff * (alg[2] * x[18] - x[22] * alg[1])) / 3;
94 der[17] = coeff * (alg[0] * x[20] - alg[2] * x[12]);
95 der[18] = ((alg[0] * x[21] - alg[2] * x[13]) * coeff) / 2;
96 der[19] = (coeff * (alg[0] * x[22] - alg[2] * x[14])) / 3;
98 der[21] = coeff * (alg[1] * x[12] - alg[0] * x[16]);
99 der[22] = (coeff * (x[13] * alg[1] - alg[0] * x[17])) / 2;
100 der[23] = (coeff * (alg[1] * x[14] - x[18] * alg[0])) / 3;
103 der[13] = coeff * (alg[2] * x[16] - alg[1] * x[20]);
104 der[14] = ((alg[2] * x[17] - x[21] * alg[1]) * coeff) / 2;
105 der[15] = (coeff * (alg[2] * x[18] - x[22] * alg[1])) / 3;
107 der[17] = coeff * (alg[0] * x[20] - alg[2] * x[12]);
108 der[18] = ((alg[0] * x[21] - alg[2] * x[13]) * coeff) / 2;
109 der[19] = (coeff * (alg[0] * x[22] - alg[2] * x[14])) / 3;
111 der[21] = coeff * (alg[1] * x[12] - alg[0] * x[16]);
112 der[22] = (coeff * (x[13] * alg[1] - alg[0] * x[17])) / 2;
113 der[23] = (coeff * (alg[1] * x[14] - x[18] * alg[0])) / 3;
116 der[13] = coeff * (alg[2] * x[16] - alg[1] * x[20]);
117 der[14] = ((alg[2] * x[17] - x[21] * alg[1]) * coeff) / 2;
118 der[15] = (coeff * (alg[2] * x[18] - x[22] * alg[1])) / 3;
120 der[17] = coeff * (alg[0] * x[20] - alg[2] * x[12]);
121 der[18] = ((alg[0] * x[21] - alg[2] * x[13]) * coeff) / 2;
122 der[19] = (coeff * (alg[0] * x[22] - alg[2] * x[14])) / 3;
124 der[21] = coeff * (alg[1] * x[12] - alg[0] * x[16]);
125 der[22] = (coeff * (x[13] * alg[1] - alg[0] * x[17])) / 2;
126 der[23] = (coeff * (alg[1] * x[14] - x[18] * alg[0])) / 3;
133 der[17] = coeff * (alg[0] * x[20] - alg[2] * x[12]);
134 der[18] = ((alg[0] * x[21] - alg[2] * x[13]) * coeff) / 2;
135 der[19] = (coeff * (alg[0] * x[22] - alg[2] * x[14])) / 3;
137 der[21] = coeff * (alg[1] * x[12] - alg[0] * x[16]);
138 der[22] = (coeff * (x[13] * alg[1] - alg[0] * x[17])) / 2;
139 der[23] = (coeff * (alg[1] * x[14] - x[18] * alg[0])) / 3;
146 der[13] = coeff * (alg[2] * x[16] - alg[1] * x[20]);
147 der[14] = ((alg[2] * x[17] - x[21] * alg[1]) * coeff) / 2;
148 der[15] = (coeff * (alg[2] * x[18] - x[22] * alg[1])) / 3;
150 der[21] = coeff * (alg[1] * x[12] - alg[0] * x[16]);
151 der[22] = (coeff * (x[13] * alg[1] - alg[0] * x[17])) / 2;
152 der[23] = (coeff * (alg[1] * x[14] - x[18] * alg[0])) / 3;
159 der[13] = coeff * (alg[2] * x[16] - alg[1] * x[20]);
160 der[14] = ((alg[2] * x[17] - x[21] * alg[1]) * coeff) / 2;
161 der[15] = (coeff * (alg[2] * x[18] - x[22] * alg[1])) / 3;
163 der[17] = coeff * (alg[0] * x[20] - alg[2] * x[12]);
164 der[18] = ((alg[0] * x[21] - alg[2] * x[13]) * coeff) / 2;
165 der[19] = (coeff * (alg[0] * x[22] - alg[2] * x[14])) / 3;
309 static const G4double sqrt3 = std::sqrt(3);
311 if ((coeff[3] == 0) || (1000 * std::fabs(coeff[3]) < std::fabs(coeff[2])))
315 else if (coeff[0] == 0)
319 mpr = -coeff[2] / coeff[3];
332 G4double val = coeff[2] / 3 / coeff[3];
333 G4double cf32 = coeff[3] * coeff[3];
334 G4double cf22 = coeff[2] * coeff[2];
336 G4double denr = 6 * coeff[3] * denq;
337 G4double rcomm = 9 * coeff[3] * coeff[2] * coeff[1] - 2 * cf22 * coeff[2];
339 q = (3 * coeff[3] * coeff[1] - cf22) / denq;
342 r = (rcomm - 27 * cf32 * coeff[0]) / denr;
349 sd = std::sqrt(disc);
354 sx = -std::cbrt(std::fabs(rsd));
361 t = -std::cbrt(std::fabs(rsd));
366 if (r1 > 0) { mpr = r1; }
371 G4double rho, th, rho13, costh3, sinth3, spt, smti32, r1;
372 rho = std::sqrt(-q3);
373 th = std::acos(r / rho);
374 rho13 = std::cbrt(rho);
375 costh3 = std::cos(th / 3);
376 sinth3 = std::sin(th / 3);
377 spt = rho13 * 2 * costh3;
378 smti32 = -rho13 * sinth3 * sqrt3;
380 if (r1 > 0) { mpr = r1; }
381 r1 = -spt / 2 - val + smti32;
382 if ((r1 > 0) && (r1 < mpr)) { mpr = r1; }
383 r1 = r1 - 2 * smti32;
384 if ((r1 > 0) && (r1 < mpr)) { mpr = r1; }
396 if (coeff[2] == 0 || (1000 * std::fabs(coeff[2])) < std::fabs(coeff[1]))
404 mpr = -coeff[0] / coeff[1];
405 mpr2 = -cf0Alt / coeff[1];
406 if (mpr < 0 || (mpr2 > 0 && mpr2 < mpr)) { mpr = mpr2; }
413 G4double cf1_2 = coeff[1] * coeff[1];
415 G4double disc1 = cf1_2 - cf2_4 * coeff[0];
416 G4double disc2 = cf1_2 - cf2_4 * cf0Alt;
419 if (
unlikely(disc1 < 0 && disc2 < 0))
426 sd = std::sqrt(disc1);
427 r1 = (-coeff[1] + sd) / cf2_d2;
433 r1 = (-coeff[1] - sd) / cf2_d2;
434 if ((r1 > 0) && (r1 < mpr)) { mpr = r1; }
439 sd = std::sqrt(disc2);
440 r1 = (-coeff[1] + sd) / cf2_d2;
446 r1 = (-coeff[1] - sd) / cf2_d2;
447 if ((r1 > 0) && (r1 < mpr)) { mpr = r1; }
452 sd1 = std::sqrt(disc1);
453 sd2 = std::sqrt(disc2);
454 r1 = (-coeff[1] + sd1) / cf2_d2;
455 r2 = (-coeff[1] + sd2) / cf2_d2;
462 r1 = (-coeff[1] - sd1) / cf2_d2;
463 if ((r1 > 0) && (r1 < mpr)) { mpr = r1; }
465 if (r2 > 0 && r2 < mpr) { mpr = r2; }
466 r2 = (-coeff[1] - sd2) / cf2_d2;
467 if ((r2 > 0) && (r2 < mpr)) { mpr = r2; }
477 static const G4double sqrt3 = std::sqrt(3);
479 if ((coeff[3] == 0) || (1000 * std::fabs(coeff[3]) < std::fabs(coeff[2])))
483 else if (coeff[0] == 0)
491 mpr2 = -coeff[2] / coeff[3];
501 if (mpr2 > 0 && mpr2 < mpr) { mpr = mpr2; }
503 else if (cf0Alt == 0)
510 mpr2 = -coeff[2] / coeff[3];
520 if (mpr2 > 0 && mpr2 < mpr) { mpr = mpr2; }
524 G4double q, r, rAlt, disc, discAlt, q3;
525 G4double val = coeff[2] / 3 / coeff[3];
526 G4double cf32 = coeff[3] * coeff[3];
527 G4double cf22 = coeff[2] * coeff[2];
529 G4double denr = 6 * coeff[3] * denq;
530 G4double rcomm = 9 * coeff[3] * coeff[2] * coeff[1] - 2 * cf22 * coeff[2];
532 q = (3 * coeff[3] * coeff[1] - cf22) / denq;
535 r = (rcomm - 27 * cf32 * coeff[0]) / denr;
536 rAlt = (rcomm - 27 * cf32 * cf0Alt) / denr;
539 discAlt = q3 + rAlt * rAlt;
545 sd = std::sqrt(disc);
550 sx = -std::cbrt(std::fabs(rsd));
557 t = -std::cbrt(std::fabs(rsd));
562 if (r1 > 0) { mpr = r1; }
566 G4double sdAlt, sAlt, tAlt, r1Alt, rsdAlt;
567 sdAlt = std::sqrt(discAlt);
568 rsdAlt = rAlt + sdAlt;
570 sAlt = std::cbrt(rsdAlt);
572 sAlt = -std::cbrt(std::fabs(rsdAlt));
575 rsdAlt = rAlt - sdAlt;
577 tAlt = std::cbrt(rsdAlt);
579 tAlt = -std::cbrt(std::fabs(rsdAlt));
582 r1Alt = sAlt + tAlt - val;
584 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
588 G4double rho, th, rho13, costh3, sinth3, spt, smti32, r1Alt;
590 rho = std::sqrt(-q3);
591 th = std::acos(rAlt / rho);
592 rho13 = std::cbrt(rho);
593 costh3 = std::cos(th / 3);
594 sinth3 = std::sin(th / 3);
595 spt = rho13 * 2 * costh3;
596 smti32 = -rho13 * sinth3 * sqrt3;
598 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
599 r1Alt = -spt / 2 - val + smti32;
600 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
601 r1Alt = r1Alt - 2 * smti32;
602 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
607 G4double rho, th, rho13, costh3, sinth3, spt, smti32, r1;
609 rho = std::sqrt(-q3);
610 th = std::acos(r / rho);
611 rho13 = std::cbrt(rho);
612 costh3 = std::cos(th / 3);
613 sinth3 = std::sin(th / 3);
614 spt = rho13 * 2 * costh3;
615 smti32 = -rho13 * sinth3 * sqrt3;
617 if (r1 > 0) { mpr = r1; }
618 r1 = -spt / 2 - val + smti32;
619 if ((r1 > 0) && (r1 < mpr)) { mpr = r1; }
620 r1 = r1 - 2 * smti32;
621 if ((r1 > 0) && (r1 < mpr)) { mpr = r1; }
625 G4double sdAlt, sAlt, tAlt, r1Alt, rsdAlt;
626 sdAlt = std::sqrt(discAlt);
627 rsdAlt = rAlt + sdAlt;
629 sAlt = std::cbrt(rsdAlt);
631 sAlt = -std::cbrt(std::fabs(rsdAlt));
634 rsdAlt = rAlt - sdAlt;
636 tAlt = std::cbrt(rsdAlt);
638 tAlt = -std::cbrt(std::fabs(rsdAlt));
641 r1Alt = sAlt + tAlt - val;
643 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
647 G4double thAlt, costh3Alt, sinth3Alt, sptAlt, smti32Alt, r1Alt;
648 thAlt = std::acos(rAlt / rho);
649 costh3Alt = std::cos(thAlt / 3);
650 sinth3Alt = std::sin(thAlt / 3);
651 sptAlt = rho13 * 2 * costh3Alt;
652 smti32Alt = -rho13 * sinth3Alt * sqrt3;
653 r1Alt = sptAlt - val;
654 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
655 r1Alt = -sptAlt / 2 - val + smti32Alt;
656 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
657 r1Alt = r1Alt - 2 * smti32Alt;
658 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }