Russ Cox presents novel algorithms for converting floating-point numbers to and from decimal text that are both simple and faster than existing methods like Dragon4, Grisu3, Ryū, and Dragonbox. The core innovation is "fast unrounded scaling" which approximates x·2^e·10^p using a single 64-bit multiplication in most cases. The post provides complete Go implementations for fixed-width printing, parsing decimals, and shortest-width printing, with detailed mathematical proofs and performance benchmarks showing significant speed improvements over prior art. The implementation is planned for Go 1.27.

41m read timeFrom research.swtch.com
Post cover image
Table of contents
IntroductionFixed-Point and Floating-Point NumbersUnrounded NumbersUnrounded ScalingFixed-Width PrintingParsing DecimalsShortest-Width PrintingFast, Accurate ScalingSketch of a Proof of Fast ScalingOmit Needless MultiplicationsPerformance

Sort: