title: Finding roots of a function with binary search and recursion
body: <p>Could someone explain, please, why we need a difference between max and min to be less than error (of the root of the cubic equation)? What is the logic behind it? And why we need to return min?</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  double func(double x)
  {
      return x * x * x  + 2 * x * x - 2;
  }
  
  double zeroFinder(double min, double max, double error)
  {
  
      if ((max - min) &lt; error)
      {
          return min;
      }
      double x = (max + min) / 2;
  
      if (func(x) &lt; 0)
      {
          min = x;
      }
      else
      {
          max = x;
      }
  
      return zeroFinder(min, max, error);
  }
  
  int main(void)
  {
       zeroFinder(0.0, 1.0, 0.01);
       zeroFinder(0.0, 1.0, 0.001);  
       zeroFinder(0.0, 1.0, 0.000001);    
       zeroFinder(0.0, 1.0, 0.0000000001);
  
       return 0;
  } 
  </code></pre>