Float compression [Re: floating point math results question]

François Pinard pinard at iro.umontreal.ca
Sun Jan 27 15:04:51 CET 2002


[François Pinard]

> > A more interesting problem is an efficient algorithm for refactoring an
> > arbitrary rational number into a sequence of the form:

> >     ... + 100.k[2] + 10.k[1] + k[0] + k[-1]/10 + k[-2]/100 + ...

> > where 0 <= k[i] < 10, which you would want for printing out the
> > representation as a normal floating point number.
> > many rationals are non-terminating as floats.]

> I would guess that `str()' has been implemented with some care about
> efficiency.  Couldn't you just use it?

Oops, sorry!  I missed the `rational' on the second quoted line, above.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list