Rationals?

Tim Peters tim.peters at gmail.com
Wed Nov 17 22:46:15 EST 2004


[Mike Meyer]
> With the decimals and the unification of int and long coming, it's
> natural (for me, anyway) to wonder how much interest there is in a
> rational type.

It is natural to wonder <wink>.

> There are two PEPs (239 and 240), and the Guido rejects them as
> no one seems interested in doing the work, but points out that the
> python distribution comes with examples/Demo/classes/Rat.py.
>
> I propose - in the spirit of "batteries included" - that Rat.py be
> cleaned up some (mostly to take advantage of the union of ints and
> longs)

+0

> and moved into the standard library.

-1

> Any good reasons not to do this?

There's no reason not to clean it up.  But Rat.py belongs where it is
regardless:  it *is* "a demo", too half-baked for the standard
library.  There's a better implementation in the Python sandbox:

    http://cvs.sf.net/viewcvs.py/python/python/nondist/sandbox/rational/

Moshe left that behind going on 4 years ago now, as a prototype for
PEP 239.  It's also far from being suitable for the standard library: 
the PEP is more a sketch of an idea than a specification, the PEP
needs to be accepted, the module needs real documentation, and it
needs a test suite.

The decimal PEP:

    http://www.python.org/peps/pep-0327.html

can serve as a good model for what PEP 239 should be.  I'll note that
at least a person-year of work has gone into 2.4's decimal
implementation, but even so decimal is still likely years away from
full integration with the language.  Nevertheless, several people
contributed major time to decimal, and that bodes well for its future.

leaky-AAA-cells-wasn't-"batteries-included"'s-intent-ly y'rs  - tim

PS:  If you simply want to *use* a high-powered rational type,
download gmpy and be happy tonight.



More information about the Python-list mailing list