This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.
fndecimalLength(v: anytype) u32 {
switch (@TypeOf(v)) {
u32, u64 => {
std.debug.assert(v < 100000000000000000);
if (v >= 10000000000000000) return17;
if (v >= 1000000000000000) return16;
if (v >= 100000000000000) return15;
if (v >= 10000000000000) return14;
if (v >= 1000000000000) return13;
if (v >= 100000000000) return12;
if (v >= 10000000000) return11;
if (v >= 1000000000) return10;
if (v >= 100000000) return9;
if (v >= 10000000) return8;
if (v >= 1000000) return7;
if (v >= 100000) return6;
if (v >= 10000) return5;
if (v >= 1000) return4;
if (v >= 100) return3;
if (v >= 10) return2;
return1;
},
u128 => {
constLARGEST_POW10 = (@as(u128, 5421010862427522170) << 64) | 687399551400673280;
varp10 = LARGEST_POW10;
vari: u32 = 39;
while (i > 0) : (i -= 1) {
if (v >= p10) returni;
p10 /= 10;
}
return1;
},
else => unreachable,
}
}