title: Fortran Floating Error while performing summation within DO loop?
body: <p>I have four double precision real numbers (n1, n2, n3, &amp; n4) in an array (n).</p>
  
  <p>The weird thing that when I calculate the sum of these four numbers within
  a DO loop and then calculate the sum directly I don't get the same exact number!</p>
  
  <p>Note that I am changing the sequence of the numbers. for example during the Do loop I go n1 + n2 + n3 + n4 but in the direct sum I go n1 + n3 + n2 + n4. Both should give the same number, but when I subtract the two results I don't get zero, instead I get a very tiny number (x10^-21)!</p>
  
  <p>Here is my Code:</p>
  
  <pre><code>PROGRAM SumFourNo
  REAL(KIND=DP) :: n(4), n_sum
  INTEGER       :: i
  
  n(1) = 9.259259259259259E-006
  n(2) = 4.629629629629630E-006
  n(3) = 9.259259259259259E-006
  n(4) = 4.629629629629630E-006
  n_sum = 0.0_DP
  
  DO i = 1 , 4
      n_sum = n_sum + n(i)
  ENDDO
  
  WRITE(*,*) 'Check =', (n(1)+n(3)+n(2)+n(4)) - n_sum
  
  ENDPROGRAM SumFourNo
  </code></pre>
  
  <p>Of course my code is way bigger than this but I don't want to confuse you so I showed you only this portion of it.</p>