3 ms·
Python 3.9.5 >>> 0.1.hex() '0x1.999999999999ap-4' >>> 0.2.hex() '0x1.999999999999ap-3' >>> (0.1 + 0.2).hex() '0x1.3333333333334p-2'
by jacobolus 5y ago
Python 3.9.5
>>> 0.1.hex()
'0x1.999999999999ap-4'
>>> 0.2.hex()
'0x1.999999999999ap-3'
>>> (0.1 + 0.2).hex()
'0x1.3333333333334p-2'
>>> 0.3.hex()
'0x1.3333333333333p-2'
- colejohnson66 5y agoBut they are repeating. So, by definition, they are not exactly representable in a (binary) floating point system. Again, that’s why 0.1 + 0.2 is not 0.3 in binary floating point.
- jacobolus 5y agoThese are not "repeating". This is showing the exact binary representation of the nearest double precision value in each case.