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 mark.dickinson
Recipients Eli.Stevens, asvetlov, belopolsky, mark.dickinson, mark.wiebe, paulehoffman, pitrou
Date 2013-04-23.17:27:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1366738035.09.0.0518889463417.issue11734@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-04-23 17:27:15mark.dickinsonsetrecipients: + mark.dickinson, belopolsky, pitrou, asvetlov, Eli.Stevens, mark.wiebe, paulehoffman
2013-04-23 17:27:15mark.dickinsonsetmessageid: <1366738035.09.0.0518889463417.issue11734@psf.upfronthosting.co.za>
2013-04-23 17:27:15mark.dickinsonlinkissue11734 messages
2013-04-23 17:27:14mark.dickinsoncreate