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.
Supplemental Material
- 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 ScholarDigital Library
- Ulf Adams. 2019. Google ScholarDigital Library
- 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 ScholarDigital Library
- Anonymous. 2018. printf format string. https://en.wikipedia.org/wiki/Printf_format_stringGoogle Scholar
- 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 Scholar
- 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 ScholarDigital Library
- Jerome Toby Coonen. 1980. An Implementation Guide to a Proposed Standard for Floating Point Arithmetic. Computer 13, 1 (Jan. 1980), 68–79. Google ScholarDigital Library
- Jerome Toby Coonen. 1981. Errata: An Implementation Guide to a Proposed Standard for Floating Point Arithmetic. Computer 14, 3 (March 1981), 62. Google ScholarDigital Library
- Free Software Foundation, Inc. 2018. GNU libc Printf Documentation. https://www.gnu.org/software/libc/manual/html_ node/Floating_002dPoint- Conversions.htmlGoogle Scholar
- David M. Gay. 1990. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Technical Report. AT&T Bell Laboratories. Numerical Analysis Manuscript 90-10.Google Scholar
- IBM. 2018. IBM Printf Documentation. https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/rtref/printf.htmGoogle Scholar
- 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 ScholarCross Ref
- Aubrey Jaffer. 2013. Easy Accurate Reading and Writing of Floating-Point Numbers. (October 2013). https://arxiv.org/abs/ 1310.8121v6 Updated January 2015.Google Scholar
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 Scholar
- 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 ScholarCross Ref
- 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 ScholarDigital Library
Index Terms
- Ryū revisited: printf floating point conversion
Recommendations
Decimal Floating-Point Multiplication
Decimal multiplication is important in many commercial applications including financial analysis, banking, tax calculation, currency conversion, insurance, and accounting. This paper presents the design of two decimal floating-point multipliers: one ...
Hardware Designs for Decimal Floating-Point Addition and Related Operations
Decimal arithmetic is often used in commercial, financial, and Internet-based applications. Due to the growing importance of decimal floating-point (DFP) arithmetic, the IEEE 754 Draft Standard for Floating-Point Arithmetic (IEEE P754) includes ...
Fast decimal floating-point division
A new implementation for decimal floating-point (DFP) division is introduced. The algorithm is based on high-radix SRT division with the recurrence in a new decimal signed-digit format. Quotient digits are selected using comparison multiples, where the ...
Comments