Rounding Bug in Python 2.0!

Gareth McCaughan Gareth.McCaughan at pobox.com
Wed Nov 1 16:14:26 EST 2000
Tim Peters wrote:

> As Thomas said, nothing changed here except the precision to which the
> interactive prompt *displays* floats.  Note also:
..
> That is, these numbers aren't exactly representable in binary
> floating-point, and never were, and "round" has nothing to do with it (well,
> not with *these* examples; the builtin "round" is sloppier than it should
> be, but these examples don't show that).

One possibility would be for Python to use, instead of the
system-provided sprintf, something like the algorithm described
in the paper "Printing floating-point numbers quickly and
accurately", by Dybvig and, er, someone whose name I've
forgotten. This guarantees to print the shortest string
that, when read in, gives exactly the value it's passed.

I'm not sure how fast this can be made, though; this might
be a reason not to do it.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
sig under construc



More information about the Python-list mailing list