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

Scott David Daniels Scott.Daniels at Acm.Org
Sun Apr 22 16:30:20 EDT 2001


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).

-Scott David Daniels







More information about the Python-list mailing list