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.

__moddi3

int.__moddi3
pub fn __moddi3(a: i64, b: i64) callconv(.c) i64

File

lib/compiler_rt/int.zig:149

Code

pub fn __moddi3(a: i64, b: i64) callconv(.c) i64 {
    // Take absolute value of a and b via abs(x) = (x^(x >> 63)) - (x >> 63).
    const abs_a = (a ^ (a >> 63)) -% (a >> 63);
    const abs_b = (b ^ (b >> 63)) -% (b >> 63);
    // Unsigned division
    var r: u64 = undefined;
    _ = __udivmoddi4(@bitCast(abs_a), @bitCast(abs_b), &r);
    // Apply the sign of the dividend and return.
    return (@as(i64, @bitCast(r)) ^ (a >> 63)) -% (a >> 63);
}