Kahan summation: Difference between revisions

Content added Content deleted
m (→‎Third phase: what is being computed?: Re-align, to hint at correspondences, and the implicit bit.)
Line 607: Line 607:
3.14159: 11.0010010000 | 11111101
3.14159: 11.0010010000 | 11111101
2.71828: +10.1011011111 | 100001001101
2.71828: +10.1011011111 | 100001001101
= 101.1101101111 |1100000011101 There should be a carry from the lower bits...
= 101.1101101111 |1100000011101 There should be a carry from the unseen lower bits...
= 101.1101110000 | 100000011101 This should be the result in the lower bits.
= 101.1101110000 | 100000011101 This should be the result in the lower bits, the carry made.
101.1101110001 ^ This is the result in the lower bits.
101.1101110001 ^ This is the calculated result in the lower bits.
Because ''both'' values round up one (because the eleventh bit is a 1) in the actual calculation, the result is one bit high. But this is entirely proper, because the eleventh bit of the sum, by sheer chance, is a 1 (as seen above: below it is a ^), and so the plain summation is as accurate as it can be and the compensated addition can't do any better. The double-precision result (from the 80-bit calculation) confirms this as the difference X4E - X8E of 4.813671112060547D-004 is 0.0000000000011111100011 in binary, exactly the last value of C.
Because ''both'' values round up one (because the eleventh bit is a 1) in the actual calculation, the result is one bit high. But this is entirely proper, because the eleventh bit of the sum, by sheer chance, is a 1 (as seen above: below it is a ^), and so the plain summation is as accurate as it can be and the compensated addition can't do any better despite all its juggling. The double-precision result (from the 80-bit calculation) confirms this as the difference X4E - X8E of 4.813671112060547D-004 is 0.0000000000011111100011 in binary, exactly the last value of C. It is calculated back-to-front compared to the hand calculation (above the ^) where the discrepancy is .0000000000100000011101: subtract one from the other and zero results, except for the last bit.
0000000000100000011101


=={{header|Go}}==
=={{header|Go}}==