5 ms·
> The usual "0.1 + 0.2 != 0.3" is _not_ imprecision. It _is_ imprecision. Even if you cannot represent 0.3 exactly, you can consider the closest representable
by SkiFire13 2mo ago
> The usual "0.1 + 0.2 != 0.3" is _not_ imprecision.
It _is_ imprecision. Even if you cannot represent 0.3 exactly, you can consider the closest representable number, and that is different than the sum of the closest numbers to 0.1 and 0.2 because doing all of this introduced imprecision.
- purplesyringa 2mo agoTo expand on this, the imprecision arises the moment you write 0.1 (decimal) in source code and the compiler converts it to binary; the arithmetic itself is (mostly) exact. So as long as you use numbers that look "good enough" in base-2, floats behave very reasonably. The constantly made assumption that floats are imprecise is, in this sense, a user error -- the user shouldn't have used decimals.