6 ms·
> I think that illusion can be a bit dangerous when we create things or use things based on that incorrect assumption. I'd be curious to hear some of the probl
by jancsika 7y ago
> I think that illusion can be a bit dangerous when we create things or use things based on that incorrect assumption.
I'd be curious to hear some of the problems programmers have run into from this conceptual discrepancy. We've got probably billions of running instances of web frameworks build atop double precision IEEE 754 to choose from. Are there any obvious examples you know?
- tomxor 7y agoI can't show you, but my job involves writing a lot of numerical grading code (as in code that grades calculated student answers in a number of different ways). I've had the pleasure of seeing many other systems pretty horrible attempts at this, both from the outside and in, in both cases numerical errors rooted in floating point math abound. To give an easy example, a common numerical property required for building formatters and graders of various aspects (scientific notation, significant figures etc), is the base 10 floored order of magnitude. The most common way of obtaining this is numerically using logarithms, but this has a number of unavoidable edge cases where it fails due to floating point error - resulting in myriad of grading errors and incorrect formatting by one sf. These are an easy target to find issues that _matter_ because users are essentially fuzzing the inputs, so they are bound to find an error if it exists, and they will also care when they do! When these oversights become a problem is very context sensitive. I suppose mine is quite biased.
- karmakaze 7y agoOperations that you think of being associative are not. A simple example is adding small and large numbers together. If you add the small numbers together and then the large one (e.g. sum from smallest to largest) the small parts are better represented in the sum than sum from largest to smallest. Could happen if you have a series of small interest payments and are applying it to the starting principal.
- Demiurge 7y agoI've worked with large datasets, aggregating millions of numbers, summing, dividing, averaging, etc... and I have tested the orders of operations, trying to force some accumulated error, and I've actually never been able to show any difference in the realm of 6-8 significant digits I looked at.
- tomxor 7y ago> in the realm of 6-8 significant digits I looked at That is far inside the range of 64bit double precision. For error to propagate up to that range of significance depends on the math, but i doubt the aggregation you are describing would cause it... provided nothing silly happens to subtotals like intermediate rounding to precision (you'd be surprised). Something like compounding as the parent was describing are far more prone to significant error propagation.
- karmakaze 7y agoI've seen rounding errors on something as simple as adding the taxes calculated per line item vs calculating a tax on a subtotal. This was flagged as incorrect downstream where taxes were calculated the other way. In a real-life transaction where pennies are not exchanged this could mean a difference of a nickel on a $20 purchase which isn't a meaningful difference but certainly not insignificant.
- Demiurge 7y agoHow much was the difference? Was there any rounding involved at any step? When dealing with money, I see rounding and integer math all the time. As another comment has mentioned, within 53 bits of mantissa, the number range is so big, we are talking 16 digits. I''d be curious to see a real-world example where the float math is the source of error, as opposed to some other bug.
- karmakaze 7y agoIt doesn't take much imagination to construct an example. Knowing 0.1 isn't exactly represented make a formula with it that should be exactly a half cent. Depending on fp I precision it will be slightly above or below a half cent and rounding will not work as expected. We found this in prod at a rate of hundreds to thousands of times per day it only takes volume to surface unlikely errors.
- Demiurge 7y ago
- deleted 7y ago[deleted]
- Const-me 7y agoWeb frameworks usually don't need floats at all. Developers working on other things encounter these problems all the time. https://randomascii.wordpress.com/category/floating-point/ https://randomascii.wordpress.com/category/floating-point/ https://stackoverflow.com/questions/46028336/inconsistent-behaviour-in-identical-code/46028887 https://stackoverflow.com/questions/46028336/inconsistent-be...
- recursive 7y agoI spent a day debugging a problem this created. Without going into irrelevant domain details, we had a set of objects, each of which has numeric properties A and B. The formal specification says objects are categorized in a certain way iff the sum of A and B is less than or equal to 0.3. The root problem, of course, was that 0.2 + 0.1 <= 0.3 isn't actually true in floating point arithmetic. It wasn't immediately obvious where the problem was since there were a lot of moving parts in play, and it did not immediately occur to us to doubt the seemingly simple arithmetic.