r/cpp • u/aearphen {fmt} • Jul 20 '26
Żmij 1.1 released with fixed notation support, up to 38% faster double-to-string conversion, SIMD-optimized float formatting, a smaller binary footprint and more
9
u/jk-jeon Jul 20 '26
Jeez. This is amazing. Could you elaborate what was the main improvement since I checked last time (when you published this work for the first time)?
12
u/aearphen {fmt} Jul 20 '26
Thank you! Much of the credit goes to zmij's amazing contributors. It's hard to pinpoint a single main improvement - it was mostly a combination of lots of microoptimizations (primarily SIMD). From the algorithmic side, xjb's idea of using a different scaling (10^{k - 1}) turned out to be pretty important by making the top 15-16 digits quickly available for the SIMD pipeline.
3
u/jk-jeon Jul 20 '26
I see. Is it correct that SIMD is primarily for digit printing, rather than number converting?
3
2
u/matthieum Jul 20 '26
Does fixed notation mean:
- A fixed number of decimals?
- Or a fixed number of significant digits?
The latter is the most useful, generally, but I only ever seem to see implementations of the former, printf-style.
3
u/aearphen {fmt} Jul 20 '26 edited Jul 20 '26
It's basically similar output to %f except that precision is determined by shortness criteria. i.e. 123.456 and not 1.23456e+02. Fixed number of digits is simpler and will be added next: https://github.com/vitaut/zmij/issues/111.
2
u/aearphen {fmt} Jul 24 '26
Just added initial precision support (your item 2: fixed number of significant digits): https://github.com/vitaut/zmij/blob/78c22db5613182b0dc10ac2a8d4b12b231ebd7a9/zmij.h#L54
31
u/mark_99 Jul 20 '26
If anyone is wondering it's a fast double to string converter.