Mark Dickinson added the comment:

Paul: your example works because struct.unpack('f', packed_stuff)[0] returns a 
regular Python float, backed by C double---i.e., exactly the same type that's 
returned by struct.unpack('d', packed_stuff)[0].  In effect, the 
single-precision C value is computed and then converted to a double-precision C 
value (a lossless conversion) before being wrapped in a Python float as usual.  
There's no dedicated float32 type, and math.isnan and math.isinf don't have to 
be aware of anything other than normal Python floats.  float16 packing and 
unpacking would work the same way: on packing, a Python float would be 
converted to the closest float16 value and then serialised to a pair of bytes; 
on unpacking, that pair of bytes is (at least conceptually) converted to a 
float16 value and then to the corresponding float64 value, wrapped up in a 
Python float.

----------

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

Reply via email to