A Revised Rational Proposal

Dan Bishop danb_83 at yahoo.com
Sun Dec 26 12:47:29 CET 2004

Mike Meyer wrote:
> This version includes the input from various and sundry people.
> to everyone who contributed.
>    <mike
> Title: A rational number module for Python
> Implicit Construction
> ---------------------
> When combined with a floating type - either complex or float - or a
> decimal type, the result will be a TypeError.  The reason for this is
> that floating point numbers - including complex - and decimals are
> already imprecise.  To convert them to rational would give an
> incorrect impression that the results of the operation are
> precise. The proper way to add a rational to one of these types is to
> convert the rational to that type explicitly before doing the
> operation.

I disagree with raising a TypeError here.  If, in mixed-type
expressions, we treat ints as a special case of rationals, it's
inconsistent for rationals to raise TypeErrors in situations where int

>>> 2 + 0.5
>>> Rational(2) + 0.5
TypeError: unsupported operand types for +: 'Rational' and 'float'

More information about the Python-list mailing list