A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/102475.html below:

PEP 240 scares me

PEP 240 scares meScottie me at nospam.net
Sun Apr 1 18:04:12 EDT 2001
Sorry, I let this go before finishing editting.

If converting to rationals scares you, try this based on James Farey's
"Farey fractions.

 def Farey(v, lim):
   '''Convert v to a rational with denom <= lim

   Named after James Farey, an English surveyor.
   No error checking on args -- v >= 0, lim = max denominator,
   results are (numerator, denominator) in lowest terms.
   Think of (1,0) as infinity.
   '''
   lower, upper = (0L,1L), (1L,0L)
   while 1:
     mediant = (lower[0] + upper[0]), (lower[1]+upper[1])
     if v * mediant[1] > mediant[0]:
         if lim < mediant[1]: return upper
         lower = mediant
     else:
         if lim < mediant[1]: return lower
         upper = mediant




More information about the Python-list mailing list

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