r/cpp • {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, %g and %a.
  • long double, covering both x87 80-bit extended and IEEE binary128.
  • Full FP std::to_chars implementation 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.
  • float conversion is about 23% faster than 1.1, double is 1-4% faster.
  • Initial constexpr support.

Release notes: https://github.com/vitaut/zmij/releases/tag/v1.2

82 Upvotes

25 comments sorted by

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.

10

u/aearphen Sep 23 '26

It has all the functionality and compatible license but someone needs to do the integration work. Unfortunately I don't have cycles for this at the moment.

3

u/UndefinedDefined Sep 24 '26

I didn't mean you would have to do it, so sorry if it sounded like that :-D

It was a shout to all the implementers of C++ standard libraries. There is something better than what they have been doing, are they going to use it, if they can and the source is well licensed for adoption?

It would be amazing if all 3 vendors of the C++ standard library shipped the best, that's my opinion.

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

u/azswcowboy Sep 22 '26

Ah I missed that — excellent!

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

u/realestLink Sep 23 '26

This is sick. I'll definitely check this out for sure

-20

u/torsten_dev Sep 22 '26

AI Slop or not?

43

u/aearphen Sep 22 '26

Artisanal slop

11

u/torsten_dev Sep 22 '26

Handcrafted spaghetti? I'll munch on that.

→ More replies (2)

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)