A rational proposal

Jp Calderone exarkun at divmod.com
Sat Dec 18 13:55:56 EST 2004


On Sat, 18 Dec 2004 12:40:04 -0600, Mike Meyer <mwm at mired.org> wrote:
>"John Roth" <newsgroups at jhrothjr.com> writes:
> 
> > "Mike Meyer" <mwm at mired.org> wrote in message
> > news:864qik472n.fsf at guru.mired.org...
> >> PEP: XXX
> >> Title: A rational number module for Python
> >> The ``Rational`` class shall define all the standard mathematical
> >> operations: addition, subtraction, multiplication, division, modulo
> >> and power.  It will also provide the methods:
> >>
> >> - max(*args): return the largest of a list of numbers and self.
> >> - min(*args): return the smallest of a list of numbers and self.
> >
> > max() and min() are already part of the standard library.
> > Providing them as instance methods is quite irregular.
> 
> They don't handle decimals or rationals. This is following the lead of
> the decimal package.

  They do handle decimals.  They handle any object which define __cmp__, 
or the appropriate rich comparison methods.

  The Decimal type seems to define min and max so that NaNs can be 
treated specially, but I glean this understanding from only a moment 
of reading decimal.py.  Perhaps someone more well informed can declare 
definitively the purpose of these methods.

  Also, note that the signatures are not Decimal.max(*args) and 
Decimal.min(*args), but rather each takes a single decimal argument 
in addition to self and an optional context argument.  So if the goal 
is symmetry with the Decimal type, then Rational.max() and 
Rational.min() should take only one argument.

  Jp



More information about the Python-list mailing list