[issue4114] struct returns incorrect 4 byte float
Mark Dickinson
report at bugs.python.org
Thu Mar 17 09:15:37 CET 2011
Mark Dickinson <dickinsm at gmail.com> added the comment:
[Robert]
> I have to disagree. It seems entirely reasonable to expect that
> unpack should return the same value passed to pack.
Robert: notice that a *Python* float (a *64-bit* C double internally) is here being stored as a *32-bit* float, losing precision. So no, it's not at all reasonable to expect that unpack should return the same value passed to pack---it's mathematically impossible for it to do so. There are (around) 2**64 distinct Python floats, and only 2**32 ways to pack them using '<f'.
When packing / unpacking using '<d', it *is* reasonable to expect the value to be recovered exactly, and as far as I know that's always what happens (barring peculiarities like NaN payloads not being reproduced exactly).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4114>
_______________________________________
More information about the Python-bugs-list
mailing list