[Python-ideas] Python Numbers as Human Concept Decimal System
Chris Angelico
rosuav at gmail.com
Sat Mar 8 03:46:14 CET 2014
On Sat, Mar 8, 2014 at 1:19 PM, Guido van Rossum <guido at python.org> wrote:
> On Fri, Mar 7, 2014 at 6:10 PM, Chris Angelico <rosuav at gmail.com> wrote:
>>
>> On Sat, Mar 8, 2014 at 1:02 PM, Guido van Rossum <guido at python.org> wrote:
>> > The repr() function does not round to a fixed number of decimals. It
>> > produces (in theory, dynamically, although I suspect that the current
>> > algorithm is better) the shortest decimal string that, when converted
>> > back
>> > to binary, equals *exactly* the input.
>>
>> 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.
I couldn't find it anywhere - help(float.__repr__) just points to it
being the implementation of repr(some_float), and poking around on the
docs didn't show up any explanation. It'd be something worth
mentioning somewhere, as that's a great feature, but I don't really
know where, heh.
ChrisA
More information about the Python-ideas
mailing list