Decimals to fraction strings
Mark Jackson
mjackson at wc.eso.mc.xerox.com
Wed May 17 07:56:51 EDT 2000
=?ISO-8859-1?Q?Fran=E7ois_Pinard?= <pinard at iro.umontreal.ca> writes:
> mjackson at wc.eso.mc.xerox.com (Mark Jackson) writes:
>
> > > Yet your suggestion is straightforward, it might not always yield the
> > > "best" answer, because of the constraint put on the denominator to
> > > initially be an exponent of 10.
>
> > <dumb look>
> > Is not this same constraint applied by the problem itself, which starts
> > with a [finite length] decimal representation?
> > </dumb look>
>
> Not necessarily. 0.6667 is well approximated by 1:3, for example, while
> if you force the denominator to be an exponent of 10, you will obtain a
> fraction which is not only uglier, but less precise.
It's only less precise if the intended result was 1/3 rather than
6667/10000, but if "0.6667" is what you're given there's no way to
tell. One could introduce an arbitrary tolerance within which a
"simpler" rational fraction is accepted (as I see you have in the
renamed thread) but in the end what you've shown is that the original
poster's approach doesn't always yield the "best" answer to a
*different* problem.
--
Mark Jackson - http://www.alumni.caltech.edu/~mjackson
In judging others, folks will work overtime for no pay.
- Charles Carruthers
More information about the Python-list
mailing list