[Python-ideas] Python Float Update

Nathaniel Smith njs at pobox.com
Mon Jun 1 04:37:14 CEST 2015

On May 31, 2015 7:26 PM, "u8y7541 The Awesome Person" <
surya.subbarao1 at gmail.com> wrote:
> Dear Python Developers:
> I will be presenting a modification to the float class, which will
improve its speed and accuracy (reduce floating point errors). This is
applicable because Python uses a numerator and denominator rather than a
sign and mantissa to represent floats.

Python's floats are in fact ieee754 floats, using sign/mantissa/exponent,
as provided by all popular CPU floating point hardware. This is why you're
getting the results you see -- 1/3 cannot be exactly represented as a
float, so it gets rounded to the closest representable float, and then
as_integer_ratio shows you an exact representation of this rounded value.
It sounds like you're instead looking for an exact fraction representation,
which in python is available in the standard "fractions" module:


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150531/d3147de9/attachment-0001.html>

More information about the Python-ideas mailing list