I have a floating point question. The following is the source code:

double sum, a[3];

int i;

sum = 0.0;

for (i=0; i < 3; i++)

sum += a[i];

printf("%e\n", sum);

sum = 0.0;

i = 3;

while (i--)

sum += a[i];

printf("%e\n", sum);

return 0;

}

As I understand, floating point has the truncation problem if there are a lot of decimal places. The sum will be different if it adds from the first element to the last element in the array and from the last one to the first one. I tried to find the sample data, unfortunately, all the data that I have used have failed. Any suggestion is greatly appreciated.

Thanks.

Eric