A floating point number has the form
where is called the mantissa
and 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 ,
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 [43],
Grisu3 [33],
Errol3 [4],
Ryū [2],
Ryū Printf [3],
Schubfach [13],
and Dragonbox [19],
and the parsing algorithm runs faster than
the Eisel-Lemire algorithm [32].
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).
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
My post “Floating-Point Printing and Parsing Can Be Simple And Fast” depends on fast unrounded scaling, defined as: The unrounded form of , , is the integer value of concatenated with two more bits: first, the “½ bit” from the binary repres
Introduction Donald Knuth wrote his 1989 paper “A Simple Program Whose Proof Isn’t” as part of a tribute to Edsger Dijkstra on the occasion of Dijkstra’s 60th birthday. Today’s post is a reply to Knuth’s paper on the occasion of Knuth’s 88t
These are the posts in the “Floating Point Formatting” series, which started in 2011 and continued in 2026. “Floating Point to Decimal Conversion is Easy” (2011) “Pulling a New Proof from Knuth’s Fixed-Point Printer” (2026) “Floating-Point
I have been debugging some code I did not write and was reminded of this technique. I’m sure it’s a very old debugging technique (like bisection), but it should be more widely known. Suppose you have one test case that’s failing. You can ge
Setting the Stage Does this sound familar? You make a change to a library to optimize its performance or clean up technical debt or fix a bug, only to get a bug report: some very large, incomprehensibly opaque test is now failing. Or you ad