New submission from Jorge Rojas <jro...@we-techs.com>:

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.

----------
components: Library (Lib)
messages: 400434
nosy: jrojas
priority: normal
severity: normal
status: open
title: struct.unpack() returns NaN
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45032>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to