PEP 240 scares me

Moshe Zadka moshez at zadka.site.co.il
Tue Mar 27 17:16:26 EST 2001


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