The following is a snippet from a C program.
Can someone please tell me why these two statements give different values even though the expressions are mathematically equivalent:
printf(" WARNING: sum = %e at time index = %d\n",C[21]*X[0] + C[22]*X[1] + C[23]*X[2] + C[24]*X[3] + C[25]*X[4] + C[26]*X[5] + C[27]*X[6],TIME_INDEX);
printf(" WARNING: sum = %e at time index = %d\n",C[21]*X[0] + C[27]*X[6] + C[22]*X[1] + C[26]*X[5] + C[23]*X[2] + C[25]*X[4] + C[24]*X[3],TIME_INDEX);
Here's the print out
WARNING: sum = -5.551115e-17 at time index = 1
WARNING: sum = 0.000000e+00 at time index = 1
The answer should be EXACTLY equal to zero. I don't understand why the order of the terms matters in the summation.
EDIT: I should say that I explicitly define that X[0] = X[6], X[1] = X[5], X[2] = X[4] prior to making the print statements.
The central difference coefficients are C[21] = -1.0/60.0; C[22] = 9.0/60.0; C[23] = -45.0/60.0; C[24] = 0.0/60.0; C[25] = 45.0/60.0; C[26] = -9.0/60.0; C[27] = 1.0/60.0;