4 ms·
The problem is that they aren't precise floats. 0.1 has no finite representation in binary. It's an infinite repeating string of digits, like 1/3rd is in decima
by slavik81 6y ago
The problem is that they aren't precise floats. 0.1 has no finite representation in binary. It's an infinite repeating string of digits, like 1/3rd is in decimal. Thus, when you add a bunch of them together, the inherent error in rounding them off at some finite number of digits slowly adds up.
The same is true of all multiples of 0.1, unless they're also a multiple of 0.5. Hence why your 60.9 is not actually 60.9. It was never exact to begin with.
- hnick 6y agoYes, that is true. But usually symptoms don't surface until errors accumulate which is why I found that web form interesting. 'Precise' was the wrong word. What I meant was the system reports back the exact entered value 0.1 (rather than what it has in memory, which is 0.100000001490116119384765625 according to https://www.h-schmidt.net/FloatConverter/IEEE754.html https://www.h-schmidt.net/FloatConverter/IEEE754.html). Most programs will do this fairly well. I confirmed javascript is entirely capable of storing and retrieving the number I entered, so I'm not entirely sure what they were doing to confuse it :) Must have been some secret maths.
- DarkWiiPlayer 6y ago> 0.1 has no finite representation in binary. b1 / b1010 I don't see the problem. Did you mean to say it has no finite representation in the IEEE float format? > It was never exact to begin with. But the format sadly gets used in situations where people expect it to be reasonably accurate, where it isn't, because developers either underestimate the "reasonable" or overestimate the "accurate" part. It's just sad that most mainstream programming languages have no native accurate data type for rational numbers.
- Gracana 6y ago> Did you mean to say it has no finite representation in the IEEE float format? Of course that's implied.
- DarkWiiPlayer 6y agoIt was a rhetoric question; I just wanted to point out that people blame these inaccuracies on "binary representations" when in reality it's just this one binary representation that's broken.
- deleted 6y ago[deleted]
- account42 6y agoSo are you saying that ⅓ has a finite presentation in decimal? Finite binary rationals ⊋ finite binary numbers.
- DarkWiiPlayer 6y ago> So are you saying that ⅓ has a finite presentation in decimal? Yes: ⅓
- slavik81 6y agoI meant in positional notation, but most people know that as "decimal notation". Unfortunately, that implies base 10, so I avoided the term. I gave both an example in binary and an example in decimal to clarify my imprecise terminology. I worry that by objecting only to the binary example, you may confuse people into thinking the two are different.