Skip to content

Commit

Permalink
Added workaround for bug signaled by Emanuele Siego
Browse files Browse the repository at this point in the history
  • Loading branch information
ebertolazzi committed Jan 15, 2021
1 parent 3d0259d commit 8e8fbe3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Binary file not shown.
14 changes: 10 additions & 4 deletions src/PolynomialRoots-3-Quartic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ namespace PolynomialRoots {
valueType t = qsolve.real_root1();
valueType s = qsolve.real_root2();

bool must_refine_r3 = true;
if ( !qsolve.complexRoots() ) {
valueType Qs = evalMonicQuartic( s, q3, q2, q1, q0 );
valueType Qu = evalMonicQuartic( u, q3, q2, q1, q0 );
Expand All @@ -521,9 +522,13 @@ namespace PolynomialRoots {
else if ( Qu <= epsi ) r3 = u;
else nreal = 0;
*/
if ( isZero(Qs) ) r3 = s;
else if ( isZero(Qu) ) r3 = u;
else nreal = 0;
if ( isZero(Qs) ) {
must_refine_r3 = false; r3 = s;
} else if ( isZero(Qu) ) {
must_refine_r3 = false; r3 = u;
} else {
nreal = 0;
}
}
} else {
// one single real root (only 1 minimum)
Expand All @@ -548,7 +553,8 @@ namespace PolynomialRoots {
.. oscillation brackets.
*/
if ( nreal > 0 ) {
iter += zeroQuarticByNewtonBisection( q3, q2, q1, q0, r3 );
if ( must_refine_r3 )
iter += zeroQuarticByNewtonBisection( q3, q2, q1, q0, r3 );
r3 *= scale;

/*
Expand Down
14 changes: 14 additions & 0 deletions src_tests/check_3_quartic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ static double quartic19[] = {
1.0 * ( -23.818259047289210 )
};

// Emanuele Siego example #2
static double rootQuarticReal20[] = { 0.14271266144792, 0.14271266144792, 0.36842201250793, 0.36842202205209 };
static double rootQuarticImag20[] = { 0.060284865351686, -0.060284865351686, 0, 0 };
static double quartic20[] = {
5.0 * ( -4.1254841444253390e+02 ),
4.0 * ( 5.9401042551598744e+02 ),
3.0 * ( -3.1743361677460911e+02 ),
2.0 * ( 7.7477065082592929e+01 ),
1.0 * ( -8.9469482641160880e+00 )
};

#define DO_TEST( N ) \
cout << "\n\nText N." << N << '\n'; \
do_test( quartic##N, rootQuarticReal##N, rootQuarticImag##N )
Expand Down Expand Up @@ -143,6 +154,7 @@ do_test(
int
main() {
cout.precision(14);
#if 1
DO_TEST(0);
DO_TEST(1);
DO_TEST(2);
Expand All @@ -163,6 +175,8 @@ main() {
DO_TEST(17);
DO_TEST(18);
DO_TEST(19);
#endif
DO_TEST(20);
cout << "\n\nALL DONE!\n";
return 0;
}
Expand Down

0 comments on commit 8e8fbe3

Please sign in to comment.