[Python-Dev] Propose rejection of PEPs 239 and 240 -- a builtin rational type and rational literals

Josiah Carlson jcarlson at uci.edu
Fri Jun 17 20:29:52 CEST 2005


"Raymond Hettinger" <raymond.hettinger at verizon.net> wrote:
> There may still be a use for a rational module in the standard library,
> but builtin support is no longer needed or desirable.

Sounds good.

> The rational proposal also has an intrinsic weakness shared with Java's
> prior versions of BigDecimal which they found to be unworkable in
> practice.  The weakness was that repeated operations caused the internal
> number of digits to grow beyond reason.  For this reason, the PEP
> proposes some arbitrary level of truncation which conflicts with the
> goals of having "obvious and exact" arithmetic.  The proposed truncation
> methodology was undeveloped and made no proposal for the same fine level
> of control as its counterpart in the decimal module where issues of
> variable precision, multiple contexts, and alternate rounding modes have
> been fully thought out.

Here is an option: exploit all of the thought and effort that has gone
into decimals.  Offer a "context" argument which handles the precision
and rounding of the rational numerator and denominator as necessary,
defaulting to the current decimal context, with automatic rounding
(using the same kinds of semantics that decimals currently uses). Offer
a mechanism by which one can use exact rationals, which use longs rather
than decimals.

The idea obviously needs fleshing out, but perhaps it is a start for
someone who wants rationals in the standard library.

 - Josiah



More information about the Python-Dev mailing list