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.
constcompiler_rt = @import("../compiler_rt.zig");
constsymbol = compiler_rt.symbol;
consttesting = @import("std").testing;
comptime {
symbol(&__addvsi3, "__addvsi3");
}
pubfn__addvsi3(a: i32, b: i32) callconv(.c) i32 {
constsum = a +% b;
// Overflow occurred iff both operands have the same sign, and the sign of the sum does
// not match it. In other words, iff the sum sign is not the sign of either operand.
if (((sum ^ a) & (sum ^ b)) < 0) @panic("compiler-rt: integer overflow");
returnsum;
}
test"addvsi3" {
// const min: i32 = -2147483648
// const max: i32 = 2147483647
// TODO write panic handler for testing panics
// try test__addvsi3(-2147483648, -1, -1); // panic
// try test__addvsi3(2147483647, 1, 1); // panic
trytesting.expectEqual(-2147483648, __addvsi3(-2147483647, -1));
trytesting.expectEqual(2147483647, __addvsi3(2147483646, 1));
}