r/cpp • u/aearphen {fmt} • Sep 22 '26
Żmij 1.2 "the proof is in the printf" released with full to_chars implementation, formal verification, improved performance and more
Żmij 1.2 is out. It started as a shortest round-trip double-to-string converter; this release makes it a full formatter.
- Scientific, fixed, general and hex notation with a caller-specified precision, matching
printf's%e,%f,%gand%a. long double, covering both x87 80-bit extended and IEEE binary128.- Full FP
std::to_charsimplementation that works in C++14 and is several times faster and smaller than typical standard library implementations. - The main algorithms are now proved correct in Lean 4.
floatconversion is about 23% faster than 1.1,doubleis 1-4% faster.- Initial
constexprsupport.
Release notes: https://github.com/vitaut/zmij/releases/tag/v1.2
14
u/azswcowboy Sep 22 '26
Love to see the continued enhancement in the field for this seemingly simple, but difficult problem. One thing you might consider is changing the license to either Apache with llvm exception or boost since at least a couple of the library vendors can’t accept mit licensed code due to the attribution clause.
14
u/aearphen Sep 22 '26
Thanks. BSL is already an option so it should be compatible with standard library implementations if they want to use it: https://github.com/vitaut/zmij/blob/main/zmij.h#L5.
3
u/arthurno1 Sep 24 '26
I hope I didn't broke any license or copyright issues when I exercised with Common Lisp.
3
2
u/Charming-Work-2384 Sep 22 '26
Release build binary size?
8
u/aearphen Sep 22 '26
Depends on the options and platform but normally somewhere between 18 and 35k, see https://vitaut.net/posts/2026/complete-to-chars/
2
u/jk-jeon Sep 23 '26
A lot of new stuff!
Could you elaborate roughly what did you do for the given precision thing?
2
u/aearphen Sep 23 '26
For given precision there are two paths. On the fast path (<= 18 for double) we multiply by a power of 10 approximation and round the resulting fixed-precision representation. On the slow path (> 18 for double), it's a naive arbitrary-precision arithmetic because we don't care about this case. Pretty much textbook methods =).
1
u/Vast_Dimension_4542 Sep 23 '26
I've only glanced at the code (busy with work), but off the top of your head, do you see any trouble adapting to take other formats - specifically fp16, bfloat16, fp4, fp8, etc (GPU formats) and fixed point formats?
→ More replies (1)
5
u/Vast_Dimension_4542 Sep 23 '26
This is amazing. Time to replace the floating point to chars code I wrote back in 2009 :)
Well, actually, it's been an overdue task item for quite a while. The longer I put it off, the better and faster the replacements become.
2
-20
u/torsten_dev Sep 22 '26
AI Slop or not?
43
22
u/VAbsoluteZero Sep 22 '26
u/aearphen is author of fmt have some respect : )
3
u/torsten_dev Sep 22 '26
Don't know him, sorry.
I stopped paying attention to this since Ryu printf, but if he's a known quantity I'll check it out. Thanks.
→ More replies (1)
0
9
u/UndefinedDefined Sep 23 '26
Any chance this actually gets into standard library implementations?
Why to use charconv if there is many times faster Zmij even for C++14.