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!

4 thoughts on “Hey, nice float!

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

    • 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 *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>