PEP 240 scares me
Scottie
me at nospam.net
Sat Mar 31 20:09:54 EST 2001
def Farey(v, 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.
(1,0) is "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
"Moshe Zadka" <moshez at zadka.site.co.il> wrote in message
news:mailman.985731647.721.python-list at python.org...
> On Tue, 27 Mar 2001 11:37:23 -0600 (CST), Skip Montanaro <skip at pobox.com>
wrote:
>
> > Okay, dumb question time. Suppose the compiler sees the string "1.2" in
the
> > input stream. How does it translate that into a rational number (6/5 or
> > 12/10 or 24/20 or ...)? Does it simply move the decimal point over
> > sufficiently and create the corresponding rational number that contains
the
> > appropriate power-of-ten denominator?
>
> That's what Rational.py (in CVS nondist/sandbox/rational/) does.
>
> > What about rationals that can't be
> > represented correctly using decimal notation (e.g. how does one get from
> > 0.3333 to 1/3, or is it simply approximated by 3333/10000?)
>
> The later. If you want 1/3, you need to ask for it:
>
> third = rational(1)/3
>
> I guess I could be bribed to have
>
> rational("0.(3)") == rational(1)/3
>
> I just need to recall the formula for the sum of a geometric series and
> apply it. There is no rational which cannot be written as
>
> \d*.\d*(\d*)
>
> Where () means "repeat ad infinitum".
> --
> "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than
Python?
> looking for someplace else to grab power."|YODA: No...no... no. Quicker,
> -- Wichert Akkerman (on debian-private)| easier, more seductive.
> For public key, finger moshez at debian.org
|http://www.{python,debian,gnu}.org
>
More information about the Python-list
mailing list