Table of Contents
Fetching ...

Converting Binary Floating-Point Numbers to Shortest Decimal Strings: An Experimental Review

Jaël Champagne Gareau, Daniel Lemire

TL;DR

When sharing or logging numerical data, the authors must convert binary floating‐point numbers into their decimal string representations, and engineers have perfected many algorithms for producing such accurate, short strings.

Abstract

When sharing or logging numerical data, we must convert binary floating-point numbers into their decimal string representations. For example, the number $π$ might become 3.1415927. Engineers have perfected many algorithms for producing such accurate, short strings. We present an empirical comparison across diverse hardware architectures and datasets. Cutting-edge techniques like Schubfach and Dragonbox achieve up to a tenfold speedup over Steele and White's Dragon4, executing as few as 210 instructions per conversion compared to Dragon4's 1500-5000 instructions. Often per their specification, none of the implementations we surveyed consistently produced the shortest possible strings-some generate outputs up to 30% longer than optimal. We find that standard library implementations in languages such as C++ and Swift execute significantly more instructions than the fastest methods, with performance gaps varying across CPU architectures and compilers. We suggest some optimization targets for future research.

Converting Binary Floating-Point Numbers to Shortest Decimal Strings: An Experimental Review

TL;DR

When sharing or logging numerical data, the authors must convert binary floating‐point numbers into their decimal string representations, and engineers have perfected many algorithms for producing such accurate, short strings.

Abstract

When sharing or logging numerical data, we must convert binary floating-point numbers into their decimal string representations. For example, the number might become 3.1415927. Engineers have perfected many algorithms for producing such accurate, short strings. We present an empirical comparison across diverse hardware architectures and datasets. Cutting-edge techniques like Schubfach and Dragonbox achieve up to a tenfold speedup over Steele and White's Dragon4, executing as few as 210 instructions per conversion compared to Dragon4's 1500-5000 instructions. Often per their specification, none of the implementations we surveyed consistently produced the shortest possible strings-some generate outputs up to 30% longer than optimal. We find that standard library implementations in languages such as C++ and Swift execute significantly more instructions than the fastest methods, with performance gaps varying across CPU architectures and compilers. We suggest some optimization targets for future research.
Paper Structure (16 sections, 1 equation, 11 figures, 11 tables)

This paper contains 16 sections, 1 equation, 11 figures, 11 tables.

Figures (11)

  • Figure 1: Conversion of a 64-bit number to a string
  • Figure 2: Python sketch of the Dragon2 steele1990print algorithm for non-negative numbers. The algorithm supports conversions between arbitrary bases, not just from base-2 to base-10. Parameters b and B denote the input and output radix, respectively. The parameter n indicates the input precision, in number of significand binary digits (e.g., the default n = 24 corresponds to binary32 precision; see Table \ref{['tab:commmonieee']}).
  • Figure 3: Python sketch of the Dragon4 steele1990print algorithm for non-negative numbers.
  • Figure 4: Python sketch of the Gay's dtoa function for non-negative numbers.
  • Figure 5: Algorithm performance (log$_{10}$ ns/f) across CPUs, compilers, and widths (mesh dataset)
  • ...and 6 more figures