[Python-3000] Reconsider repr(0.1) == '0.10000000000000001'

Noam Raphael noamraph at gmail.com
Sun Dec 9 18:38:17 CET 2007


Great! He also provides C code, in
http://www.cs.indiana.edu/~burger/fp/index.html

The license says: "All software (c) 1996 Robert G. Burger. Permission
is hereby granted, free of charge, to any person obtaining a copy of
this software, to deal in the software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the software." I guess
it means that it can be used.

Does anyone have any objections in principle for a patch based on his
code that will shorten the repr() of floats while preserving
"eval(repr(f)) == f"? If not, I'll try to write it in the next few
days.

(I checked - indeed, the current implementation just uses the OS's
conversion method with 17 precision digits.)

Noam

2007/12/9, Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl>:
> Dnia 09-12-2007, N o godzinie 10:33 +0200, Noam Raphael pisze:
>
> > I think that the reason for the long representation is that it uses a
> > simple algorithm that makes "eval(repr(f)) == f" always true. However,
> > why not use another, a bit more complex, algorithm, which will still
> > preserve "eval(repr(f)) == f", but which will shorten the result when
> > it can?
>
> "Printing Floating-Point Numbers Quickly and Accurately"
> Robert G. Burger, R. Kent Dybvig
>
> http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
> http://www.cs.indiana.edu/~burger/
>
> I used this algorithm for my language Kogut.
>
> --
>    __("<         Marcin Kowalczyk
>    \__/       qrczak at knm.org.pl
>     ^^     http://qrnik.knm.org.pl/~qrczak/
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/noamraph%40gmail.com
>


More information about the Python-3000 mailing list