[issue1682] Move Demo/classes/Rat.py to Lib/rational.py and fix it up.

Guido van Rossum report at bugs.python.org
Thu Jan 10 01:38:35 CET 2008


Guido van Rossum added the comment:

On Jan 9, 2008 4:29 PM, Raymond Hettinger <report at bugs.python.org> wrote:
> I think the history of rational modules is that simplistic
> implementations get built and then the writers find that exploding
> denominators limit their usefulness for anything other than trivial
> problems.  The solution is to limit denominators but that involves less
> trivial algorithms and a more sophisticated API.

A "rational" type that limits denominators (presumably by rounding)
isn't needed -- we alreay have Decimal.  The proposed rational type is
meant for "pure" mathematical uses, just like Python's long ints.

Regarding float->rational, I propose to refuse Rational(1.1) for the
same reasons as Decimal(1.1) is refused, but to add a separate
constructor (a class method?) that converts a float to a rational
exactly (as long as it isn't nan or inf), large denominators be
damned. This can help people who are interested in taking floating
point numbers apart.

float(Rational()) should be fine.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1682>
__________________________________


More information about the Python-bugs-list mailing list