Using fractions instead of floats

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Oct 4 19:20:15 EDT 2007


On Tue, 02 Oct 2007 06:07:15 +0000, Rhamphoryncus wrote:

> On Sep 30, 7:35 pm, andresj <andres.j.... at gmail.com> wrote:
>> I was doing some programming in Python, and the idea came to my mind:
>> using fractions instead of floats when doing 2/5.
> 
> The core problem with rationals (other than the inability to handle
> irrationals) 

If that's a problem, it is one shared by ints and floats.


> is their tendency to require more and more memory as
> calculations progress.  This means they get mysteriously slower and
> slower.
> 
> http://mail.python.org/pipermail/python-list/2002-October/166630.html

I've read that thread, and although I see the claim made that rationals 
are slow, I don't see the claim that they get "mysteriously" slower as 
calculations progress. (And if they did, it would hardly be a mystery if 
we know it is because they use more memory.)

I guess that could occur with unlimited precision rationals, in the same 
way that it could occur with ever-larger longints, but I don't see how it 
could occur with a simpler, limited precision implementation.



-- 
Steven.



More information about the Python-list mailing list