How about adding rational fraction to Python?

Jeff Schwab jeff at
Wed Feb 27 05:06:16 CET 2008

Mark Dickinson wrote:
> On Feb 26, 9:00 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>> Certainly, I'd expect that if x and y are both integers and x is an
>> exact multiple of y, then x/y will be computable and not overflow.
>> But try computing 10**5000 / 10**4000 under future division (that is
>> supposed to give a float).
> And smaller numbers are problematic too:
>>>> from __future__ import division
>>>> 10**50/10**40
> 10000000000.0
>>>> 10**60/10**50
> 9999999999.9999981
> This despite the fact that the quotient *is* exactly representable

You know what I find weird about this?  The result of truncating 
division in this case is not just less accurate than it could be; it's 
actually greater than the result of non-truncating division.

 >>> (10**60//10**50) > (10**60/10**50)

More information about the Python-list mailing list