A Revised Rational Proposal

John Roth newsgroups at jhrothjr.com
Sun Dec 26 08:30:42 EST 2004


"Dan Bishop" <danb_83 at yahoo.com> wrote in message 
news:1104061649.243801.12940 at c13g2000cwb.googlegroups.com...
> 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
> 




More information about the Python-list mailing list