Hey, nice float!

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!

This entry was posted in Math, Project, Python. Bookmark the permalink.

4 Responses to Hey, nice float!

  1. 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…

  2. 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.

  3. shouldn’t this be in the standard library?
    so where’s the patch for Lib/repr.py?


  4. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *