On Jan 21, 11:32 pm, Kenneth Lundström <kenneth.t.lundst...@gmail.com> wrote: > This returns -5.68434188608e-14 not 0 as you would expect, or?
>>> 0.1 0.10000000000000001 >>> 1/10, and many other values, are not precisely representable in 64-bit floating point. Worse, adding or subtracting two floating-point numbers of very different magnitudes generates a significant error when dealing with many values: >>> 1e8 + 1e-8 100000000.00000001 >>> 1e9 + 1e-9 1000000000.0 Now imagine you sum a great many small numbers, and you keep a running total. It is possible that eventually your cumulative total simply doesn't change, even though there is a non-negligible sum of the values that are now literally being discarded because the precision of the cumulative sum is not great enough to capture them. Basically, floating point sucks, which is why many financial software packages encode currency values as integers, offset by milli-cents or something similar.