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 loewis
Recipients TD22057, loewis, vstinner
Date 2008-10-13.22:36:05
SpamBayes Score 2.553513e-15
Marked as misclassified No
Message-id <48F3CD53.6040505@v.loewis.de>
In-reply-to <1223936823.38.0.583103993855.issue4114@psf.upfronthosting.co.za>
Content
> Don't hesitate to reopen the bug if you consider that
> something should be fixed in Python.

I agree that it should be closed; people should read general CS
introductory material to learn how floating point numbers work.

> @loewis: Yes, the initial problem is about unpack("f", bytes). It's 
> not possible to exact original 32 bits float value

Interestingly enough, it is possible - using the OPs approach.
If you want to truncate a 64-bit floating point number to a
32-bit one, pack it as float in the struct module, then unpack it.
Python will automatically pad the mantissa bytes with null bytes.

> because Python 
> forces a conversion to 64 bits float. The behaviour should be 
> documented. 

I think it's documented somewhere that a Python float is represented
with a C double. That should suffice, IMO.
History
Date User Action Args
2008-10-13 22:36:06loewissetrecipients: + loewis, vstinner, TD22057
2008-10-13 22:36:05loewislinkissue4114 messages
2008-10-13 22:36:05loewiscreate