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/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4