]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
fixed the function and the test
authorvp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Mon, 18 Jan 2010 23:25:40 +0000 (23:25 +0000)
committervp153 <vp153@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Mon, 18 Jan 2010 23:25:40 +0000 (23:25 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@2577 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/src/cxcore/cxmathfuncs.cpp
opencv/tests/cxcore/src/asolvepoly.cpp

index c03954ef536fd9034f56f89beaf54167ae49ba43..13d7043d5e136950ac0d25a07a1d82338eb8c84d 100644 (file)
@@ -2009,10 +2009,10 @@ double cv::solvePoly( const Mat& coeffs0, Mat& roots0, int maxIters )
         for( i = 0; i < n; i++ )
         {
             p = roots[i];
-            C num = coeffs[0], denom = 1;
+            C num = coeffs[n], denom = 1;
             for( j = 0; j < n; j++ )
             {
-                num = num*p + coeffs[j+1];
+                num = num*p + coeffs[n-j-1];
                 if( j != i ) denom = denom * (p - roots[j]);
             }
             num /= denom;
index 0f56441498cd48334b689375d49ffe108e005b8f..1f9305df03ee7b34647fe065b5c08c0f0485d8ed 100644 (file)
@@ -7,14 +7,12 @@
 #include <vector>
 #include <iostream>
 
-#if 0
-
 typedef std::complex<double> complex_type;
 
 struct pred_complex {
     bool operator() (const complex_type& lhs, const complex_type& rhs) const
     {
-        return lhs.real() != rhs.real() ? lhs.real() < rhs.real() : lhs.imag() < rhs.imag();
+        return fabs(lhs.real() - rhs.real()) > fabs(rhs.real())*FLT_EPSILON ? lhs.real() < rhs.real() : lhs.imag() < rhs.imag();
     }
 };
 
@@ -76,7 +74,7 @@ void CV_SolvePolyTest::run( int )
 
         bool pass = false;
         double div;
-        for (int maxiter = 10; !pass && maxiter < 10000; maxiter *= 2)
+        for (int maxiter = 100; !pass && maxiter < 10000; maxiter *= 2)
         {
             for (int j = 0; j < n + 1; ++j)
                    a[j] = c[j].real();
@@ -113,10 +111,9 @@ void CV_SolvePolyTest::run( int )
             ts->printf( CvTS::LOG, "\n" );
             for (size_t j=0;j<ar.size();++j)
                    ts->printf( CvTS::LOG, "ar[%d]=(%g, %g)\n", j, ar[j].real(), ar[j].imag());
+            break;
         }
     }
 }
 
 CV_SolvePolyTest solve_poly_test;
-
-#endif