[issue4114] struct returns incorrect 4 byte float
Raymond Hettinger
report at bugs.python.org
Thu Mar 17 19:21:48 CET 2011
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
The suggested examples are misleading because they use 6.24 which is not exactly representable in binary floating point. Representation issues are orthogonal to the OP's issue which is really just a simple rounding example:
>>> x = float.fromhex('0x0.1234560000001')
>>> unpack('!f', pack('!f', x))[0].hex()
'0x1.2345600000000p-4'
Also, if something like the suggested note is adopted, it needs to be worded in a way that doesn't imply that the struct implementation is broken or misdesigned.
A better note would focus on the basic (and obvious) fact that downgrading from double precision to single precision
entails a loss of precision.
----------
nosy: +rhettinger
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4114>
_______________________________________
More information about the Python-bugs-list
mailing list