alt.hn

1/19/2026 at 10:21:45 PM

Floating-Point Printing and Parsing Can Be Simple and Fast

https://research.swtch.com/fp

by chmaynard

1/20/2026 at 2:10:04 PM

The shortest double-to-string algorithm is basically Schubfach or, rather, it's variation Tejú Jaguá with digit output from Dragonbox. Schubfach is a beautiful algorithm: I implemented and wrote about it in https://vitaut.net/posts/2025/smallest-dtoa/. However, in terms of performance you can do much better nowadays. For example, https://github.com/vitaut/zmij does 1 instead of 2-3 costly 128x64-bit multiplications in the common case and has much more efficient digit output.

by vitaut

1/23/2026 at 10:49:24 PM

I have been using Walter Bright's libc code from Zortech-C for microcontrollers, where I care about code size more than anything else:

https://github.com/nklabs/libnklabs/blob/main/src/nkprintf_f... https://github.com/nklabs/libnklabs/blob/main/src/nkstrtod.c https://github.com/nklabs/libnklabs/blob/main/src/nkdectab.c

nkprintf_fp.c+nkdectab.c: 2494 bytes

schubfach.cc: 10K bytes.. the code is small, but there is a giant table of numbers. Also this is just dtoa, not a full printf formatter.

OTOH, the old code is not round-trip accurate.

Russ Cox should make a C version of his code..

by jhallenworld

1/25/2026 at 5:08:22 PM

Schubfach, Ryū, Dragonbox etc support round-tripping and shortest-width, which (it sounds like) is not important for you. The idea of round-tripping is that if you convert a double to a string and then parse that, you get the exact same value. Shortest-width is to correctly round and generate the shortest possible text. I tried to implement a version that does _just_ round-tripping but is not shortest-width, it is around 290 lines for both parsing and toString [1]

[1] https://github.com/thomasmueller/bau-lang/blob/main/src/test...

by thomasmg

1/23/2026 at 10:58:25 PM

I implemented Teju Jaguá in Rust, based of the original C impl https://github.com/andrepd/teju-jagua-rs. Comparing to Zmij, I do wonder how much speedup is there on the core part of the algorithm (f2^e -> f10^e) vs on the printing part of the problem (f*10^e -> decimal string)! Benchmarks on my crate show a comparable amount of time spent on each of those parts.

by andrepd

1/24/2026 at 3:27:22 AM

I don't have exact numbers but from measuring perf changes per commit it seemed that most improvements came from "printing" (e.g. switching to BCD and SIMD, branchless exponent output) and microoptimizations rather than algorithmic improvements.

by vitaut

1/23/2026 at 11:54:36 PM

What about reasonably fast but smallest code, for running on a microcontroller? Anything signifactly better in terms of compiled size (including lookups)?

by magicalhippo

1/24/2026 at 3:24:34 AM

If you compress the table (see my earlier comment) and use plain Schubfach then you can get really small binary size and decent perf. IIRC Dragonbox with the compressed table was ~30% slower which is a reasonable price to pay and still faster than most algorithms including Ryu.

by vitaut

1/24/2026 at 3:28:13 AM

When 30% is only ~3-6 ns it definitely seems worthwhile.

by adgjlsfhk1

1/24/2026 at 3:49:55 PM

Note that ~3-6ns is on modern desktop CPUs where extra few kB matter less. On microcontrollers it will be larger in absolute terms but I would expect the relative difference to also be moderate.

by vitaut

1/24/2026 at 3:54:16 AM

Rust's `serde_json` recently switched to use a new library for floating string conversion: https://github.com/dtolnay/zmij.

by WiSaGaN

1/24/2026 at 3:50:39 PM

I was impressed how fast the Rust folks adopted this! Kudos to David Tolnay and others.

by vitaut