[Python-Dev] Re: Adding a Rational Type to Python

Moshe Zadka moshez@zadka.site.co.il
Mon, 12 Mar 2001 03:00:25 +0200 (IST)


On Sun, 11 Mar 2001, Guido van Rossum <guido@digicool.com> wrote:

> I believe that a fourth PEP should be written as well: decimal
> floating point.  Maybe Tim can draft this?

Better. I have very little decimal point experience, and in any way
I'd find it hard to write a PEP I don't believe it. However, I would
rather that it be written if only to be officially rejected, so if
no one volunteers to write it, I'm willing to do it anyway.
(Besides, I might manage to actually overtake Jeremy in number of PEPs
if I do this)

> It's kind of sneaky not to mention in the abstract that this should be
> the default representation for numbers containing a decimal point,
> replacing most use of floats!

I beg the mercy of the court. This was here, but got lost in the editing.
I've put it back.

> This PEP definitely needs a section of arguments Pro and Con.  For
> Con, mention at least that rational arithmetic is much slower than
> floating point, and can become *very* much slower when algorithms
> aren't coded carefully.

Note that I did try to help with coding carefully by adding the ".trim"
method.

> There are also backwards compatibility issues at the C level.

Hmmmmm....what are those? Very few c functions explicitly expect a
float, and the responsibility here can be pushed off to the Python
programmer by having to use explicit floats. For the others, PyArg_ParseTuple
can just coerce to float with the "d" type.

> Question: the time module's time() function currently returns a
> float.  Should it return a rational instead?  This is a trick question.

It should return the most exact number the underlying operating system
supports. For example, in OSes supporting gettimeofday, return a rational
built from tv_sec and tv_usec.
-- 
"I'll be ex-DPL soon anyway so I'm        |LUKE: Is Perl better than Python?
looking for someplace else to grab power."|YODA: No...no... no. Quicker,
   -- Wichert Akkerman (on debian-private)|      easier, more seductive.
For public key, finger moshez@debian.org  |http://www.{python,debian,gnu}.org