[Python-ideas] Python Numbers as Human Concept Decimal System

Eric V. Smith eric at trueblade.com
Sat Mar 8 03:50:22 CET 2014


On 3/7/2014 9:19 PM, Guido van Rossum wrote:
> On Fri, Mar 7, 2014 at 6:10 PM, Chris Angelico <rosuav at gmail.com
> <mailto:rosuav at gmail.com>> wrote:
>     If that's the definition of a float's repr, then I'd support using
>     that by default for the construction of a Decimal from a float. You
>     can always use .as_integer_ratio() to get the exact stored
>     representation.
> 
> 
> Sadly I can't point to exactly where this is documented, but since
> Python 2.7 and some early version of 3.x that is indeed how
> repr(<float>) works.

It's mentioned at the bottom of this page:
http://docs.python.org/2/tutorial/floatingpoint.html

But oddly the wording in
http://docs.python.org/3/tutorial/floatingpoint.html is not as precise.
There are some weasel words in there because we do have a fallback if we
can't run Gay's code on some systems (sys.float_repr_style='legacy').
But I think for all practical purposes it's always true.

> (And str(<float>) too -- before 2.7, str() would give only 12 digits
> while repr() gave 17, but the new repr() makes such shenanigans
> unnecessary. So I could have saved myself a few characters by using
> str() instead of repr() everywhere in this thread. :-)

Indeed!

Eric.


More information about the Python-ideas mailing list