PEP239 (Rational Numbers) Reference Implementation and new issues

Christian Tismer tismer at tismer.com
Wed Oct 9 20:14:12 EDT 2002


Chris Gonnerman wrote:
[snipped all the other good stuff]

> Practicality beats purity.

Absolutely.

> If you don't believe me:
> 
>     >>> import this
>     The Zen of Python, by Tim Peters
> 
>     << hack >>
>     Although practicality beats purity.
>     << hack >>
> 
> Yeah, I'm the one who has been arguing in favor of a
> decimal arithmetic type in the standard library.  Ask 
> me to support rationals in the standard library, and I'll
> back you up.  Heck, I'll even accept (optional) rational
> literals, like the way we do longs.  (As long as you 
> support (optional) decimal literals in return... :-)

Ok, we have a deal.

> But I don't want to see rationals if I haven't asked for
> them.  I'm sure nobody wants to see decimals if they
> haven't asked for them, either.  Principle of least
> surprise... if a program I wrote for an earlier version
> suddenly starts taking much, much longer to run (maybe
> worse: much, much longer *sometimes*), it may cost me a
> lot of time to fix it up.

Naa, this is slightly different.
I don't think al too many people asked for an integer
in the first place when they wrote

   1/3

, they just got a zero "since it is so in Python".

Now suddenly for some reason out of this thread's scope
Python reconsiders and thinks it should change this.
So the target of this whole thing is (AFAIK) to figure
out which type to return as the result of integer division?

> I agree, 
> 
>     1/3
> 
> is pretty nice as a rational literal; but would it hurt 
> so much to say 
> 
>     1/3R
> 
> instead?

So you would suggest to stick with 1/3 == 0, or return
a float, or a rational?
The latter makes no sense, since this would save the R.

Personally, I don't like the idea to change 1/3 at all
not very much. I see Python doing too much adjustments
at the moment.
Making 1/3 return a float felt like a bad idea, after it
had been int for so many years. Enforcing the float
has become a habit where it's needed.
Now, returning a true fraction instead sounds exciting.
Having fractions in the language is exciting as well,
after I had them in Mathematica for long years.

Finally, if I had to choose, I would either stick with
the old truncation, or use rationals.
Rationals would be welcome, even if there were just
an extension module.

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  pager +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/






More information about the Python-list mailing list