This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jrojas
Recipients jrojas
Date 2021-08-27.17:13:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1630084418.34.0.275202976554.issue45032@roundup.psfhosted.org>
In-reply-to
Content
Hi all!

I have this case when trying to get a float value applying pack to these integer values:
struct.unpack('f', struct.pack('HH', 0, 32704))

This happens when executing the unpack function to a float format, from a bit-array where the sign bit is not in a suitable position I think. Applying big-endian to the format, it returns a numeric value, but being little-endian it returns a NaN.

> struct.unpack('<f', struct.pack('HH',0, 32704))
Out[168]: (nan,)
> struct.unpack('>f', struct.pack('HH',0, 32704))
Out[169]: (6.905458702346266e-41,)

The current documentation on struct.unpack doesn't anything about what conditions a NaN is returned, besides this might be a expected value. Maybe explaining how this value could be converted to an equivalent format to retrieve the proper value may help, or why this returns a NaN and how to avoid it.

Thanks in advance.
History
Date User Action Args
2021-08-27 17:13:38jrojassetrecipients: + jrojas
2021-08-27 17:13:38jrojassetmessageid: <1630084418.34.0.275202976554.issue45032@roundup.psfhosted.org>
2021-08-27 17:13:38jrojaslinkissue45032 messages
2021-08-27 17:13:38jrojascreate