[Python-Dev] Re: PEP239 (Rational Numbers) Reference Implementation and new issues
Oren Tirosh
oren-py-d@hishome.net
Wed, 9 Oct 2002 10:13:06 +0200
On Tue, Oct 08, 2002 at 10:18:46PM -0400, Tim Peters wrote:
> > 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 trailing 'r' *is* rational notation, and stuff like this probably isn't
> a good idea for str():
I'm not sure I follow. What 'stuff' is not a good idea for str() and why?
By rational notation I meant the division form, not the trailing r or any
other syntax used by the language to indicate the type.
>
> > #e6.02e-45
> 301/50000000000000000000000000000000000000000000000
> >
>
> 6.02e-45r would be clearer to virtually anyone.
Again, I'm not sure I follow your logic. How likely is an arbitrary
rational number to have a denominator ending with lots of zeros?
> > (+ 312 (/ 1 3))
> 937/3
> >
>
> would likely be clearer to virtually anyone as 312+1/3r too.
Yes, in this case it is much clearer.
> But most of all, I agree that if you're working with rationals, you don't
> want to lose information silently, not even in a "pleasant" string.
>
> > 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'
>
> 2/3r works for both for me. 0.666...7 doesn't work for me at all as a
> stringification of a rational (if I want to approximate, I'll ask for an
> approximation).
Works for repr, str, or both? The str() of long omits the trailing L.
I don't think rationals should show the trailing r.
Oren