From: Vadim Pisarevsky Date: Sun, 7 Nov 2010 19:23:48 +0000 (+0000) Subject: correct 2 bugs in cvSolveCubic (linear and quadratic cases: tickets #525 and #364) X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~8477 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=402ef4c9cb2f69627ca80d602b928e56056e1a2a;p=platform%2Fupstream%2Fopencv.git correct 2 bugs in cvSolveCubic (linear and quadratic cases: tickets #525 and #364) --- diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index 56a06ec..c56312a 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -2285,7 +2285,7 @@ cvSolveCubic( const CvMat* coeffs, CvMat* roots ) else { // linear equation - x0 = a3/a2; + x0 = -a3/a2; n = 1; } } @@ -2296,9 +2296,18 @@ cvSolveCubic( const CvMat* coeffs, CvMat* roots ) if( d >= 0 ) { d = sqrt(d); - double q = (-a2 + (a2 < 0 ? -d : d)) * 0.5; - x0 = q / a1; - x1 = a3 / q; + double q1 = (-a2 + d) * 0.5; + double q2 = (a2 + d) * -0.5; + if( fabs(q1) > fabs(q2) ) + { + x0 = q1 / a1; + x1 = a3 / q1; + } + else + { + x0 = q2 / a1; + x1 = a3 / q2; + } n = d > 0 ? 2 : 1; } }