Movatterモバイル変換
[0]ホーム
ANN: Experimental Number Types (Integer, Rational, Floats)
M.-A. Lemburgmal 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 algorithmusing GMP ... if you can point me to a proof that it actually doeswork in all cases ;-)BTW, I believe that "Concrete Mathematics" (by Knuth, Patashnik)will most likely have similar algorithms which may be useful in thiscontext -- 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-listmailing list
[8]ページ先頭