[math-fun] How do you print a number? DUHHHHH!!!!!!!
You have a 64-bit IEEE floating point real. You wish to print it in decimal in the format 1.2345e17. Note: Any such real always has a finite-length printout. But here is the thing: I want that printout to be accurate. If you, during the conversion to base 10, make any roundoff error at all, then you lose. If you are required to make the printout fit inside N characters, then roundoff is ok, but only the smallest possible roundoff error consistent with fitting the output into N characters. (W.Edwin Clark and I are wondering whether the C printf function actually does the right thing, or whether for like 30 freaking years they've been using a bogus print function without telling anybody.) A google search found the following paper about their former paper with same title: Guy L. Steele Jr. & Jon L White: How to Print Floating-Point Numbers Accurately http://grouper.ieee.org/groups/754/email/pdfq3pavhBfih.pdf where it said the former paper was "20 years in the making." If it took them 20 years to figure it out, and they published in >=1990, then I claim that the authors of the C language could not know about this paper, hence quite likely they screwed it up. Further, this paper contains various depressing words, indicating the considerable likelihood that a programming language near you has a print statement which does not work.
Here are two papers on this topic cited in the Steele-White retrospective: David M. Gay: Correctly Rounded Binary-Decimal and Decimal-Binary Conversions (1990) http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.31.4049&rep=rep1&typ... Gay's algorithm is implemented (I think) inside his language AMPL, and also available from netlib. Robert Burger , R. Kent Dybvig: Printing Floating-Point Numbers Quickly and Accurately, http://citeseer.ist.psu.edu/viewdoc/download;jsessionid=EC593AC56FA08763D0A9... They say Steele & White's print algorithm is "unacceptably slow for practical use." B&D's algorithm is implemented inside "chez scheme." It seems to me all these algorithms are VERY complicated. There must be something better than any of them... -- Warren D. Smith http://RangeVoting.org <-- add your endorsement (by clicking "endorse" as 1st step)
Have you found any with C source that uses no libraries other than POSIX standard? On 8/31/12, Warren Smith <warren.wds@gmail.com> wrote:
Here are two papers on this topic cited in the Steele-White retrospective:
David M. Gay: Correctly Rounded Binary-Decimal and Decimal-Binary Conversions (1990) http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.31.4049&rep=rep1&typ... Gay's algorithm is implemented (I think) inside his language AMPL, and also available from netlib.
Robert Burger , R. Kent Dybvig: Printing Floating-Point Numbers Quickly and Accurately, http://citeseer.ist.psu.edu/viewdoc/download;jsessionid=EC593AC56FA08763D0A9... They say Steele & White's print algorithm is "unacceptably slow for practical use." B&D's algorithm is implemented inside "chez scheme."
It seems to me all these algorithms are VERY complicated. There must be something better than any of them...
-- Robert Munafo -- mrob.com Follow me at: gplus.to/mrob - fb.com/mrob27 - twitter.com/mrob_27 - mrob27.wordpress.com - youtube.com/user/mrob143 - rilybot.blogspot.com
* Warren Smith <warren.wds@gmail.com> [Sep 01. 2012 11:55]:
You have a 64-bit IEEE floating point real. You wish to print it in decimal in the format 1.2345e17. [...]
First check how MPFR handles the problem (assuming it is addressed), see http://www.mpfr.org/ I also guess (the bibliography of) Jean-Michel Muller, Nicolas Brisebarre, Florent de Dinechin, \ Claude-Pierre Jeannerod, Vincent Lef\`{e}vre, Guillaume Melquiond, \ Nathalie Revol, Damien Stehl\'{e}, Serge Torres: {Handbook of Floating-Point Arithmetic}, Birkh\"{a}user, (2010). % http://www.springer.com/birkhauser/mathematics/book/978-0-8176-4704-9 should be interesting.
participants (3)
-
Joerg Arndt -
Robert Munafo -
Warren Smith