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 standard library. Public Function
pubfnwrap(x: anytype, r: anytype) @TypeOf(x) {
constinfo_x = @typeInfo(@TypeOf(x));
constinfo_r = @typeInfo(@TypeOf(r));
if (info_x == .intandinfo_x.int.signedness != .signed) {
@compileError("x must be floating point, comptime integer, or signed integer.");
}
switch (info_r) {
.int => {
// in the rare usecase of r not being comptime_int or float,// take the penalty of having an intermediary type conversion,// otherwise the alternative is to unwind iteratively to avoid overflowconstR = @Int(.signed, info_r.int.bits + 1);
constradius: if (info_r.int.signedness == .signed) @TypeOf(r) elseR = r;
return@intCast(@mod(x - radius, 2 * @as(R, r)) - r); // provably impossible to overflow
},
else => {
return@mod(x - r, 2 * r) - r;
},
}
}
Odd sawtooth function
Limit x to the half-open interval [-r, r).