Ryū revisited: printf floating point conversion

Ulf Adams
2019
4 citations
2 references

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.

1 repository
2 references

Code References

llvm/llvm-project
2 files
libc/src/stdio/printf_core/float_dec_converter.h
1
L485 // https://doi.org/10.1145/3360595
libc/src/__support/float_to_string.h
1
L85 // https://doi.org/10.1145/3360595
Link copied to clipboard!