Żmij :dragon:

May 8, 2026 · View on GitHub

Zig implementation of a fast floating point to string conversion algorithm

Inspirations:

  1. Victor Zverovich's C/C++ implementation - Reference Implementation
  2. David Tolnay's Rust implementation

Example

const zmij = @import("zmij.zig");
const expectEqualStrings = @import("std").testing.expectEqualStrings;

pub fn main() !void {
    var buf = zmij.Buffer{};
    const printed = buf.format(1.234);
    try expectEqualStrings("1.234e+00", printed);
}

Benchmark

The code has been benchmarked against std.fmt and the results are as follows:

Value(std.fmt)Avg. Time (ns)Value(zmij)Avg. Time (ns)
1.23456e246.4770421.23456e215.358958
3.141592653589793e023.6189173.141592653589793e018.435417
1e-2053.5395841e-2014.902084
1.2345678901234567e30024.8508751.2345678901234567e30018.55775
0e014.4320e00.910042

To run it on your own machine, use:

zig build bench -Doptimize=ReleaseFast