ANN: Experimental Number Types (Integer, Rational, Floats)

M.-A. Lemburg mal at lemburg.com
Mon Apr 23 08:15:05 EDT 2001


Scott David Daniels wrote:
> 
> Would it be rude to point to the farey function I've thrown in the Python
> Cookbook here?
>     http://www.activestate.com/ASPN/Python/Cookbook/Recipe/52317
> I know I had a hard time figuring out how to go from floating point (or more
> generally a value of any kind) to a rational approximation.  The function
> above shows how to get there if you can do multiplication and comparison
> reasonably efficiently.  You could even use it to go from some fairly
> high-precision Rational to a lower-precision rational (say, from
> Rational(333, 106) to Rational(22,7) for example).

Looks interesting. If I find time, I'll recode the algorithm
using GMP ... if you can point me to a proof that it actually does
work in all cases ;-)

BTW, I believe that "Concrete Mathematics" (by Knuth, Patashnik)
will most likely have similar algorithms which may be useful in this
context -- long time since I last had a look at that book...

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Pages:                           http://www.lemburg.com/python/




More information about the Python-list mailing list