A program stores its numbers as 32-bit float values. These values have limited precision: for example, storing 100000001 gives 100000000. An addition also rounds its result to the nearest value that a float can store.
You can explore this behavior with Float Toy.
Three numbers. Let a = 1, b = 100000000, and c = -100000000. All three are stored exactly. Evaluating the following expressions gives the shown results:
(a + b) + c /* observed result: 0 */
a + (b + c) /* observed result: 1 */A longer sum. The program next adds one number equal to 100000000 and 128 numbers equal to 1. If it starts with 100000000 and adds each 1 separately, the stored total remains 100000000. However, both 128 and 100000128 can be represented exactly as floats. You may change the order or grouping of the additions, but you must still use float arithmetic.
A different addition function. A function named precise_sum promises the same result as adding its input values exactly and then rounding the total to a float.
The program reads the original decimal measurements, stores each one as a float, and then passes those stored values to precise_sum.
