[Python-ideas] Python Float Update

random832 at fastmail.us random832 at fastmail.us
Mon Jun 1 05:37:17 CEST 2015

On Sun, May 31, 2015, at 23:21, Jim Witschey wrote:
> I think hiding hardware number implementations has been a success for
> integers - it's a far superior API. It could be for rationals as well.

I'd worry about unbounded complexity. For rationals, unlike integers,
values don't have to be large for their bignum representation to be

> Has something like this thread's original proposal - interpeting
> decimal-number literals as fractional values and using fractions as the
> result of integer arithmetic - been seriously discussed more recently
> than
> PEP 240? If so, why haven't they been implemented? Perhaps enough has
> changed that it's worth reconsidering.

Also, it raises a question of string representation. Granted, "1/3"
becomes much more defensible as the repr of Fraction(1, 3) if it in fact
evaluates to that value, but how much do you like "6/5" as the repr of
1.2? Or are we going to use Fractions for integer division and Decimals
for literals? And, what of decimal division? Right now you can't even
mix Fraction and Decimal in arithmetic operations.

And are we going to add %e %f and %g support for both types? Directly
so, without any detour to float and its limitations (i.e. %.100f gets
you 100 true decimal digits of precision)?

Current reality:
>>> '%.50f' % Fraction(1, 3)
>>> '%.50f' % Decimal('0.3333333333333333333333333333333333333')
>>> '{:.50f}'.format(Fraction(1, 3))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: non-empty format string passed to object.__format__
>>> '{:.50f}'.format(Decimal('0.3333333333333333333333333333333333'))

Okay, that's one case right out of four.

More information about the Python-ideas mailing list