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.
constsymbol = @import("../compiler_rt.zig").symbol;
consttesting = @import("std").testing;
comptime {
symbol(&__addvdi3, "__addvdi3");
}
pubfn__addvdi3(a: i64, b: i64) callconv(.c) i64 {
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"addvdi3" {
// const min: i64 = -9223372036854775808
// const max: i64 = 9223372036854775807
// TODO write panic handler for testing panics
// try test__addvdi3(-9223372036854775808, -1, -1); // panic
// try test__addvdi3(9223372036854775807, 1, 1); // panic
trytesting.expectEqual(-9223372036854775808, __addvdi3(-9223372036854775807, -1));
trytesting.expectEqual(9223372036854775807, __addvdi3(9223372036854775806, 1));
}