title: how to sum a large number of float number?
body: <p>I build a paralle sum code to sum a large number of float numbers then I found when the number of figures is bigger than 100000000, the result will go wrong. Then I build a serial code to compare. The serial code also get wrong number. Anybody knows why? Thanks!</p>
  
  <p>my simple code is as follows.</p>
  
  <p>the result is " 1.67772e+007". It should be 1e+008</p>
  
  <pre><code>int main()
  {
      size_t N=100000000;
      cout&lt;&lt;"n is : "&lt;&lt;N&lt;&lt;endl;
      clock_t start = clock();
      task_scheduler_init init;
      vector&lt;float&gt; myvec;
      vector&lt;float&gt;* pvec;
      for(int i=0;i&lt;N;i++)
          myvec.push_back(1.0f);
      pvec=&amp;myvec;
      float mysum;
      mysum=parallelSum(pvec);
      cout&lt;&lt;" the p sum is: "&lt;&lt;mysum&lt;&lt;endl;
      clock_t finish = clock();
          cout&lt;&lt;"Time Used  = "&lt;&lt;(finish - start)/CLOCKS_PER_SEC&lt;&lt;endl;
          mysum=0;
         for(int i=0;i&lt;N;i++)
      mysum+=myvec[i];
          cout&lt;&lt;" the s sum is: "&lt;&lt;mysum&lt;&lt;endl;
      return 0;
  }
  </code></pre>