3 ms·
My favorite floating point weirdness is that 0.1 can't be exactly represented in floating point.
by lifefeed 4y ago
My favorite floating point weirdness is that 0.1 can't be exactly represented in floating point.
- jrockway 4y agoIsn't it equally weird that 1/3 can't be exactly represented in decimal?
- kps 4y agoIndeed, 0.1 can be represented exactly in decimal floating point, and can't be represented in binary fixed point. It's just that fractional values are currently almost always represented using binary floating point, so the two get conflated.
- pitaj 4y agoYep! Too bad humanity has settled on decimal instead of dozenal (base 12).
- astrange 4y agoImperial units were right all along.
- layer8 4y agoThe reason why the 0.1 case is weird (unexpected) is that we use decimal notation in floating-point constants (in source code, in formats like JSON, and in UI number inputs), but the value that the constant actually ends up representing is really the closest binary number, where in addition the closeness depends on the FP precision used. If we would write FP values in binary or hexadecimal (which some languages support), the issue wouldn’t arise.