PEP 240 scares me

Alex Martelli aleaxit at yahoo.com
Tue Mar 27 14:08:10 EST 2001


"Skip Montanaro" <skip at pobox.com> wrote in message
news:15040.53203.949420.930912 at beluga.mojam.com...
>
>     Alex> AFAIK -- 1.2 would be the rational 6/5
>
> 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?

Moshe will have to confirm his intent, but I'd be astonished if it
did anything but that.

> 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?)

0.3333 is _exactly_ represented by 3333/10000; the approximation
would be that of this exact rational with the different one 1/3.


Alex






More information about the Python-list mailing list