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.

medium

rem_pio2.medium
fn medium(ix: u32, x: f64, y: *[2]f64) i32

File

lib/compiler_rt/rem_pio2.zig:28

Code

fn medium(ix: u32, x: f64, y: *[2]f64) i32 {
    var w: f64 = undefined;
    var t: f64 = undefined;
    var r: f64 = undefined;
    var @"fn": f64 = undefined;
    var n: i32 = undefined;
    var ex: i32 = undefined;
    var ey: i32 = undefined;
    var ui: u64 = undefined;

    // rint(x/(pi/2))
    @"fn" = x * invpio2 + toint - toint;
    n = @intFromFloat(@"fn");
    r = x - @"fn" * pio2_1;
    w = @"fn" * pio2_1t; // 1st round, good to 85 bits
    // Matters with directed rounding.
    if (r - w < -pio4) {
        n -= 1;
        @"fn" -= 1;
        r = x - @"fn" * pio2_1;
        w = @"fn" * pio2_1t;
    } else if (r - w > pio4) {
        n += 1;
        @"fn" += 1;
        r = x - @"fn" * pio2_1;
        w = @"fn" * pio2_1t;
    }
    y[0] = r - w;
    ui = @bitCast(y[0]);
    ey = @intCast((ui >> 52) & 0x7ff);
    ex = @intCast(ix >> 20);
    if (ex - ey > 16) { // 2nd round, good to 118 bits
        t = r;
        w = @"fn" * pio2_2;
        r = t - w;
        w = @"fn" * pio2_2t - ((t - r) - w);
        y[0] = r - w;
        ui = @bitCast(y[0]);
        ey = @intCast((ui >> 52) & 0x7ff);
        if (ex - ey > 49) { // 3rd round, good to 151 bits, covers all cases
            t = r;
            w = @"fn" * pio2_3;
            r = t - w;
            w = @"fn" * pio2_3t - ((t - r) - w);
            y[0] = r - w;
        }
    }
    y[1] = (r - y[0]) - w;
    return n;
}