Message187658
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. |
|
Date |
User |
Action |
Args |
2013-04-23 17:27:15 | mark.dickinson | set | recipients:
+ mark.dickinson, belopolsky, pitrou, asvetlov, Eli.Stevens, mark.wiebe, paulehoffman |
2013-04-23 17:27:15 | mark.dickinson | set | messageid: <1366738035.09.0.0518889463417.issue11734@psf.upfronthosting.co.za> |
2013-04-23 17:27:15 | mark.dickinson | link | issue11734 messages |
2013-04-23 17:27:14 | mark.dickinson | create | |
|