PEP 240 scares me
Paul Prescod
paulp at ActiveState.com
Tue Mar 27 14:37:23 EST 2001
Skip Montanaro 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?
My understanding is that it moves the decimal point over and then it
factors out common factors from the top and bottom.
> 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 has no relation to 1/3. If you want 1/3 you would just type 1/3.
The idea is that division would yield rationals also!
--
Take a recipe. Leave a recipe.
Python Cookbook! http://www.activestate.com/pythoncookbook
More information about the Python-list
mailing list