title: Optimize floating-point calculations
body: <p>I have a task to make the following function as precise (the speed is not the aim) as possible. I <em>have to</em> use <em>float</em> and the <em>method of middle rectangles</em>. Could you suggest something? Actually, I think, it's all about minimization of float rounding errors. That's what I've done:</p>
  
  <pre><code>typedef float T;
  
  T integrate(T left, T right, long N, T (*func)(T)) {
      long i = 0;
      T result = 0.0;
      T interval = right - left;
      for(i = 0; i &lt; N; i++) {
          result += func(left + interval * (i + 0.5) / N) * interval / N;
      }
      return result;
  }
  </code></pre>