How about adding rational fraction to Python?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Feb 27 00:33:44 EST 2008


En Wed, 27 Feb 2008 00:39:09 -0200, Mark Dickinson <dickinsm at gmail.com>  
escribió:
> 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
> as a float...

But:
py> 10**60//10**50
10000000000L

Nobody has menctioned yet the -Q command line option: -Qwarn will issue a  
warning when 3/4 is executed.
And there is a helper script, Tools\scripts\fixdiv.py, that helps on  
locating and replacing / operators.  It works by analyzing the warnings  
issued when the target program is actually executed with -Qwarnall.
There is also a companion script, finddiv.py, that just scans the source  
looking for / and /= operators.
They exist since this semantic change was introduced *seven* *years* ago,  
in 2001, so it's not that suddenly the Python world is going to be upside  
down... I can't believe how long this thread is by now...

-- 
Gabriel Genellina




More information about the Python-list mailing list