475 {
477 static const G4double sqrt3 = std::sqrt(3);
478
479 if ((coeff[3] == 0) || (1000 * std::fabs(coeff[3]) < std::fabs(coeff[2])))
480 {
482 }
483 else if (coeff[0] == 0)
484 {
488
489 if (coeff[1] == 0)
490 {
492 }
493 else
494 {
499 }
500
501 if (mpr2 > 0 && mpr2 < mpr) { mpr = mpr2; }
502 }
503 else if (cf0Alt == 0)
504 {
507
508 if (coeff[1] == 0)
509 {
511 }
512 else
513 {
518 }
519
520 if (mpr2 > 0 && mpr2 < mpr) { mpr = mpr2; }
521 }
522 else
523 {
524 G4double q, r, rAlt, disc, discAlt, q3;
531
533 q3 = q * q * q;
534
535 r = (rcomm - 27 * cf32 *
coeff[0]) / denr;
536 rAlt = (rcomm - 27 * cf32 * cf0Alt) / denr;
537
538 disc = q3 + r * r;
539 discAlt = q3 + rAlt * rAlt;
541
542 if (disc >= 0)
543 {
545 sd = std::sqrt(disc);
546 rsd = r + sd;
547 if (rsd > 0) {
548 sx = std::cbrt(rsd);
549 } else {
550 sx = -std::cbrt(std::fabs(rsd));
551 }
552
553 rsd = r - sd;
554 if (rsd > 0) {
555 t = std::cbrt(rsd);
556 } else {
557 t = -std::cbrt(std::fabs(rsd));
558 }
559
560 r1 = sx + t - val;
561
562 if (r1 > 0) { mpr = r1; }
563
564 if (discAlt >= 0)
565 {
566 G4double sdAlt, sAlt, tAlt, r1Alt, rsdAlt;
567 sdAlt = std::sqrt(discAlt);
568 rsdAlt = rAlt + sdAlt;
569 if (rsdAlt > 0) {
570 sAlt = std::cbrt(rsdAlt);
571 } else {
572 sAlt = -std::cbrt(std::fabs(rsdAlt));
573 }
574
575 rsdAlt = rAlt - sdAlt;
576 if (rsdAlt > 0) {
577 tAlt = std::cbrt(rsdAlt);
578 } else {
579 tAlt = -std::cbrt(std::fabs(rsdAlt));
580 }
581
582 r1Alt = sAlt + tAlt - val;
583
584 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
585 }
586 else
587 {
588 G4double rho, th, rho13, costh3, sinth3, spt, smti32, r1Alt;
589
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;
597 r1Alt = spt - val;
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; }
603 }
604 }
605 else
606 {
607 G4double rho, th, rho13, costh3, sinth3, spt, smti32, r1;
608
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;
616 r1 = spt - val;
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; }
622
623 if (discAlt >= 0)
624 {
625 G4double sdAlt, sAlt, tAlt, r1Alt, rsdAlt;
626 sdAlt = std::sqrt(discAlt);
627 rsdAlt = rAlt + sdAlt;
628 if (rsdAlt > 0) {
629 sAlt = std::cbrt(rsdAlt);
630 } else {
631 sAlt = -std::cbrt(std::fabs(rsdAlt));
632 }
633
634 rsdAlt = rAlt - sdAlt;
635 if (rsdAlt > 0) {
636 tAlt = std::cbrt(rsdAlt);
637 } else {
638 tAlt = -std::cbrt(std::fabs(rsdAlt));
639 }
640
641 r1Alt = sAlt + tAlt - val;
642
643 if (r1Alt > 0 && r1Alt < mpr) { mpr = r1Alt; }
644 }
645 else
646 {
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; }
659 }
660 }
661 }
662
663 return mpr;
664 }
G4double min_pos_root_3(G4double *coeff)
G4double min_pos_root_2_alt(G4double *coeff, G4double cf0Alt)