skip to main content

Ryū revisited: printf floating point conversion

Published:10 October 2019Publication History
Skip Abstract Section

Abstract

Ryū Printf is a new algorithm to convert floating-point numbers to decimal strings according to the printf %f, %e, and %g formats: %f generates ‘full’ output (integer part of the input, dot, configurable number of digits), %e generates scientific output (one leading digit, dot, configurable number of digits, exponent), and %g generates the shorter of the two. Ryū Printf is based on the Ryū algorithm, which converts binary floating-point numbers to the shortest equivalent decimal floating-point representation. We provide quantitative evidence that Ryū Printf is between 3.8 and 55 times faster than existing printf implementations.

Furthermore, we show that both Ryū and Ryū Printf generalize to arbitrary number bases. This finding implies the existence of a fast algorithm to convert from base-10 to base-2, as long as the maximum precision of the input is known a priori.

Skip Supplemental Material Section

Supplemental Material

a169-adams.webm

webm

153 MB

References

  1. Ulf Adams. 2018. Ry ¯ u: Fast Float-to-String Conversion. In Proceedings of the 39th ACM SIGPLAN 2018 Conference on Programming Language Design and Implementation (PLDI 2018). ACM, New York, NY, USA, 270–282. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Ulf Adams. 2019. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Marc Andrysco, Ranjit Jhala, and Sorin Lerner. 2016. Printing Floating-point Numbers: A Faster, Always Correct Method. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’16). ACM, New York, NY, USA, 555–567. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Anonymous. 2018. printf format string. https://en.wikipedia.org/wiki/Printf_format_stringGoogle ScholarGoogle Scholar
  5. Nikolay Petrovich Brusentsov and José Ramil Alvarez. 2011. Ternary Computers: The Setun and the Setun 70. In Perspectives on Soviet and Russian Computing, John Impagliazzo and Eduard Proydakov (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg, 74–80.Google ScholarGoogle Scholar
  6. Robert G. Burger and R. Kent Dybvig. 1996. Printing Floating-point Numbers Quickly and Accurately. In Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation (PLDI ’96). ACM, New York, NY, USA, 108–116. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Jerome Toby Coonen. 1980. An Implementation Guide to a Proposed Standard for Floating Point Arithmetic. Computer 13, 1 (Jan. 1980), 68–79. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Jerome Toby Coonen. 1981. Errata: An Implementation Guide to a Proposed Standard for Floating Point Arithmetic. Computer 14, 3 (March 1981), 62. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Free Software Foundation, Inc. 2018. GNU libc Printf Documentation. https://www.gnu.org/software/libc/manual/html_ node/Floating_002dPoint- Conversions.htmlGoogle ScholarGoogle Scholar
  10. David M. Gay. 1990. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Technical Report. AT&T Bell Laboratories. Numerical Analysis Manuscript 90-10.Google ScholarGoogle Scholar
  11. IBM. 2018. IBM Printf Documentation. https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/rtref/printf.htmGoogle ScholarGoogle Scholar
  12. IEEE Computer Society. Microprocessor Standards Committee and Institute of Electrical and Electronics Engineers and IEEE-SA Standards Board. 2008. 754-2008 - IEEE Standard for Floating-Point Arithmetic. Institute of Electrical and Electronics Engineers (IEEE), New York. Google ScholarGoogle ScholarCross RefCross Ref
  13. Aubrey Jaffer. 2013. Easy Accurate Reading and Writing of Floating-Point Numbers. (October 2013). https://arxiv.org/abs/ 1310.8121v6 Updated January 2015.Google ScholarGoogle Scholar
  14. Donald Ervin Knuth. 1997. The Art of Computer Programming (3rd ed.). Vol. II: Seminumerical Algorithms. Addison-Wesley, Boston, Massachusetts, United States, Chapter 4.4 Radix Conversion, p. 326.Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Florian Loitsch. 2010. Printing Floating-Point Numbers Quickly and Accurately with Integers. In Proceedings of the ACM SIGPLAN 2010 Conference on Programming Language Design and Implementation, PLDI 2010. ACM, New York, NY, USA, 233–243. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Microsoft. 2016. Microsoft Visual Studio 2017: Format specification syntax: printf and wprintf functions. https://docs.microsoft. com/en- us/cpp/c- runtime- library/format- specification- syntax- printf- and- wprintf- functions?view=vs- 2017Google ScholarGoogle Scholar
  17. Klaus Samelson and Friedrich L. Bauer. 1953. Optimale Rechengenauigkeit bei Rechenanlagen mit gleitendem Komma. Zeitschrift für angewandte Mathematik und Physik (ZAMP) 4, 4 (Jul 1953), 312–316. Google ScholarGoogle ScholarCross RefCross Ref
  18. Guy L. Steele, Jr. and Jon L. White. 1990. How to Print Floating-point Numbers Accurately. In Proceedings of the ACM SIGPLAN 1990 Conference on Programming Language Design and Implementation (PLDI ’90). ACM, New York, NY, USA, 112–126. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Ryū revisited: printf floating point conversion

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader