title: Incorrect Output when applying Divide & Conquer
body: <p>I have to solve an one-root equation in an interval, using Divide &amp; Couquer. Here is my code:</p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  
  double coef[4];
  int d=3;
  
  double f(double x){
      int i;
      double res;
      for(i=0;i&lt;=d;i++) res+=coef[i]*pow(x,i);
      return res;
  }
  
  double solve(double left,double right){
      double mid=(left+right)/2;
  
      if(abs(f(mid))&lt;=1e-8) return mid;
      if(right-left&lt;=1e-4) return mid;
  
      printf("%.4f %.4f %.4f\n",left,mid,right);
  
      if(f(mid)*f(left)&gt;=0) return solve(mid,right); 
      if(f(mid)*f(right)&gt;=0) return solve(left,mid);
  }
  
  int main(){
  
      coef[0]=-10;
      coef[1]=0;
      coef[2]=0;
      coef[3]=1.5;
  
      printf("%lf\n",solve(-10,10));
  }
  </code></pre>
  
  <p>Then I use it to solve <code>1.5x^3-10=0</code> with two bound <code>-10</code> and <code>10</code>, but it seems to me that <code>if(f(mid)*f(right)&gt;=0) return solve(left,mid);</code> doesn't work at all.</p>
  
  <pre><code>-10.0000 0.0000 10.0000
  0.0000 5.0000 10.0000
  5.0000 7.5000 10.0000
  7.5000 8.7500 10.0000
  8.7500 9.3750 10.0000
  9.3750 9.6875 10.0000
  9.6875 9.8438 10.0000
  9.8438 9.9219 10.0000
  9.9219 9.9609 10.0000
  9.9609 9.9805 10.0000
  ...
  </code></pre>
  
  <p>I know that the root of the equation is <code>1.8821</code> so the output is incorrect.</p>
  
  <p>The same happens with <code>[-20, 20]</code>.</p>
  
  <p>If I test with <code>[-1.000.000, 1.000.000]</code> the output gives me the root <code>500000.0000</code> which is clearly incorrect.</p>
  
  <p>So what's wrong with my function <code>solve()</code>?</p>
  
  <p>Any help will be highly appreciated!</p>