Zig 0.17.0-dev (Split by item)

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.

signedRemainder

C % operator for signed integers C standard states: "If the quotient a/b is representable, the expression (a/b)*b + a%b shall equal a" The quotient is not representable if denominator is zero, or if numerator is the minimum integer for the type and denominator is -1. C has undefined behavior for those two cases; this function has safety checked undefined behavior

helpers.signedRemainder
pub fn signedRemainder(numerator: anytype, denominator: anytype) @TypeOf(numerator, denominator)

File

Code

pub fn signedRemainder(numerator: anytype, denominator: anytype) @TypeOf(numerator, denominator) {
    std.debug.assert(@typeInfo(@TypeOf(numerator, denominator)).int.signedness == .signed);
    if (denominator > 0) return @rem(numerator, denominator);
    return numerator - @divTrunc(numerator, denominator) * denominator;
}