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.
fnsqrt_int(comptimeT: type, value: T) Sqrt(T) {
if (@typeInfo(T).int.bits <= 2) {
returnif (value == 0) 0else1; // shortcut for small number of bits to simplify general case
} else {
constbits = @typeInfo(T).int.bits;
constmax = math.maxInt(T);
constminustwo = (@as(T, 2) ^ max) + 1; // unsigned int cannot represent -2varop = value;
varres: T = 0;
varone: T = 1 << ((bits - 1) & minustwo); // highest power of four that fits into T
// "one" starts at the highest power of four <= than the argument.
while (one > op) {
one >>= 2;
}
while (one != 0) {
constc = op >= res + one;
if (c) op -= res + one;
res >>= 1;
if (c) res += one;
one >>= 2;
}
return@as(Sqrt(T), @intCast(res));
}
}