4 ms·
> people flinch at inconsistencies, 0.1 + 0.2 = 0.3 is an identity and when basic identities are wrong people feel uncomfortable and don't want to proceed; if y
by crote 3y ago
> people flinch at inconsistencies, 0.1 + 0.2 = 0.3 is an identity and when basic identities are wrong people feel uncomfortable and don't want to proceed; if you are working with an accountant, for instance, and they see something that is not consistent in a way they've been trained has to be consistent, they will just stop until it is consistent.
This is an unsolvable problem. If your floats are base-10 "0.1 + 0.2 = 0.3" might work out, but it isn't going to fix "(1/3)3 = 1". And it gets even worse if you do anything involving π.
It is mathematically impossible for a computer to handle all* reals correctly, so something has to give. Binary floats are a reasonable approximation in practice, and anyone wanting something else is free to use arbitrary-precision libraries.
- PaulHoule 3y agoIn Jupyter I just wrote (1/3.0)*3.0-1.0==0.0 and got back the answer True no problem there.
- constantcrying 3y agoThe guy you replied to was talking about base 10 floats. As you can very easily see his example has to work if the arithmetic has the "best possible" property and the rounding mode is "to nearest". Pythons is unusable for numerics without numpy, which makes it a tiny bit less unusable.