3 ms·
I also posted this below as a reply. Python uses David Gay's algorithm for printing the shortest equivalent floating point representation. Implementation deta
by jamesdutc 11y ago
I also posted this below as a reply.
Python uses David Gay's algorithm for printing the shortest equivalent floating point representation.
Implementation details and discussion are available from the Python bug tracker:
https://bugs.python.org/issue1580 https://bugs.python.org/issue1580
There are a few broken links. I believe the original poster references the following paper by Robert Burger & Kent Dybvig, "Printing Floating-Point Numbers Quickly and Accurately":
http://www.cs.indiana.edu/~dyb/pubs/FP-Printing-PLDI96.pdf http://www.cs.indiana.edu/~dyb/pubs/FP-Printing-PLDI96.pdf
There's also a reference to the following paper by William Clinger, "How to Read Floating Point Numbers Accurately":
http://www.cesura17.net/~will/professional/research/papers/retrospective.pdf http://www.cesura17.net/~will/professional/research/papers/r...
ftp://ftp.ccs.neu.edu/pub/people/will/retrospective.pdf
I believe this is the David Gay paper, "Correctly Rounded Binary-Decimal and Decimal-Binary Conversions":
http://www.ampl.com/REFS/rounding.pdf http://www.ampl.com/REFS/rounding.pdf
By the way, this has previously been discussed on HN (which is where I think I first read all of this...):
https://news.ycombinator.com/item?id=2708983 https://news.ycombinator.com/item?id=2708983
- 3JPLW 11y agoThere's also the GRISU algorithm: http://dl.acm.org/citation.cfm?id=1806623 http://dl.acm.org/citation.cfm?id=1806623