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.

nrand48

drand48.nrand48
fn nrand48(xsubi: *[3]c_ushort) callconv(.c) c_long

File

lib/c/stdlib/drand48.zig:52

Code

fn nrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
    const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);

    var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
    const next_xi = separate_lcg.next();

    xsubi.* = .{ @truncate(next_xi & 0xFFFF), @truncate((next_xi >> 16) & 0xFFFF), @truncate((next_xi >> 32) & 0xFFFF) };
    return @intCast(next_xi >> 17); // a c_long is always at least 32-bits, this is never UB
}