python-nicefloat is a Python module implementing an algorithm based on the paper “Printing Floating-Point Numbers Quickly and Accurately”, by Robert G. Burger and R. Kent Dybvig.
The implemented algorithm will find the shortest, correctly rounded output string representing a decimal number that converts to the same internal binary floating-point number when read.
Update: the download link is now fixed.
Have fun!
http://codespeak.net/svn/pypy/dist/pypy/lib/_float_formatting.py
Unless you’ve implemented the fixed format routines as well, in which case PyPy is interested :)
It’s a bit hard to tell though as it looks like you forgot to upload the file…
Hello Michael,
Oops.. sorry about that. The file was there, but the hack I made in moin to show up urls at labix.org/download was broken for page names including ‘-‘. It’s fixed now.
I have not implemented the fixed format routines because I was really after the free format one (and you already had it, right? :-) ), but reading the paper it looks like a small change in the free format one.
If you’re looking for it, I may give it a try.
shouldn’t this be in the standard library?
so where’s the patch for Lib/repr.py?
</F>
Yes, I think it should. Indeed, I think the standard float.__repr__ should be implemented using that algorithm. Anyway, since it’s not, I’ll prepare a patch to put it in the stdlib.