[Python-Dev] Re: PEP239 (Rational Numbers) Reference Implementation and new issues
Oren Tirosh
oren-py-d@hishome.net
Wed, 9 Oct 2002 02:02:12 +0200
On Tue, Oct 08, 2002 at 12:09:57PM -0400, Guido van Rossum wrote:
>
> > '3/5'
>
> I'd like at least one of those return '0.6' or '0.6r'.
Why should any of them go through a potetially lossy transformation?
If you need to approximate a ratio as a finite decimal fraction it should
be explicit: str(float(r)).
I think it will also make a good visual cue to always use rational notation
for rationals and decimal fractions for floats.
The result of repr() should eval() back to exactly the same object. The
result of str() should be the 'pretty' representation because this is the
form displayed by print statements and %s formatting. I find '2/3' prettier
than '0.666666666667'
pretty-is-in-the-eyes-of-the-beholder-ly yours,
Oren