"Dan Bishop" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
Mike Meyer wrote:
This version includes the input from various and sundry people.
Thanks
to everyone who contributed.

   <mike

PEP: XXX
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 doesn't.

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

I agree that the direction of coercion should be toward the floating type, but Decimal doesn't combine with Float either. It should be both or neither.

John Roth


John Roth


-- http://mail.python.org/mailman/listinfo/python-list

Reply via email to