TECH Signal 390
The fastest double-to-string algorithm you’ve never heard of
Illustration only Photo by Mitchell Luo on Unsplash
An algorithm called yy from the yyjson library performs double-to-string conversion using only one multiplication by a precomputed power of 10, reducing the overhead compared to classic Schubfach implementations.
Engineers working on high-throughput JSON parsing can replace existing dtoa routines with this fixed-width integer approach to cut multiplication costs. The trade-off is managing the specific boundary cases and subnormal paths the algorithm requires to maintain correct round-trip behavior.
Written by elseif from the cluster below · every claim links back to a sourceThe three things worth knowing
The yy algorithm finds the shortest decimal string that round-trips back to a binary float using fixed-width integer arithmetic.
It reduces multiplication overhead by deriving the half-ulp rounding band delta via an integer shift of the precomputed power-of-10 table value rather than a separate multiplication.
The algorithm selects from four decimal candidates using three predicates that implement round-half-to-even logic at exact ties.
THE CLUSTER