Floating-Point Printing and Parsing Can Be Simple and Fast

https://news.ycombinator.com/rss Hits: 2
Summary

Floating-Point Printing and Parsing Can Be Simple And Fast Russ Cox January 19, 2026 research.swtch.com/fp Posted on Monday, January 19, 2026. PDF Introduction A floating point number f has the form f=m·2e where m is called the mantissa and e is a signed integer exponent. We like to read numbers scaled by powers of ten, not two, so computers need algorithms to convert binary floating-point to and from decimal text. My 2011 post “Floating Point to Decimal Conversion is Easy” argued that these conversions can be simple as long as you don’t care about them being fast. But I was wrong: fast converters can be simple too, and this post shows how. The main idea of this post is to implement fast unrounded scaling, which computes an approximation to x·2e·10p, often in a single 64-bit multiplication. On that foundation we can build nearly trivial printing and parsing algorithms that run very fast. In fact, the printing algorithms run faster than all other known algorithms, including Dragon4 [], Grisu3 [], Errol3 [], Ryū [], Ryū Printf [], Schubfach [], and Dragonbox [], and the parsing algorithm runs faster than the Eisel-Lemire algorithm []. This post presents both the algorithms and a concrete implementation in Go. I expect some form of this Go code to ship in Go 1.27 (scheduled for August 2026). This post is rather long—far longer than the implementations!—so here is a brief overview of the sections for easier navigation and understanding where we’re headed. “Fixed-Point and Floating-Point Numbers” briefly reviews fixed-point and floating-point numbers, establishing some terminology and concepts needed for the rest of the post. “Unrounded Numbers” introduces the idea of unrounded numbers, inspired by the IEEE754 floating-point extended format. “Unrounded Scaling” defines the unrounded scaling primitive. “Fixed-Width Printing” formats floating-point numbers with a given (fixed) number of decimal digits, at most 18. “Parsing Decimals” parses decimal numbers of at most 19 dig...

First seen: 2026-01-23 20:48

Last seen: 2026-01-23 21:49