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.

rem_pio2f

rem_pio2f.rem_pio2f
pub fn rem_pio2f(x: f32, y: *f64) i32

File

lib/compiler_rt/rem_pio2f.zig:23

Code

pub fn rem_pio2f(x: f32, y: *f64) i32 {
    var tx: [1]f64 = undefined;
    var ty: [1]f64 = undefined;
    var @"fn": f64 = undefined;
    var ix: u32 = undefined;
    var n: i32 = undefined;
    var sign: bool = undefined;
    var e0: u32 = undefined;
    var ui: u32 = undefined;

    ui = @bitCast(x);
    ix = ui & 0x7fffffff;

    // 25+53 bit pi is good enough for medium size
    if (ix < 0x4dc90fdb) { // |x| ~< 2^28*(pi/2), medium size
        // Use a specialized rint() to get fn.
        @"fn" = @as(f64, @floatCast(x)) * invpio2 + toint - toint;
        n = @intFromFloat(@"fn");
        y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;
        // Matters with directed rounding.
        if (y.* < -pio4) {
            n -= 1;
            @"fn" -= 1;
            y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;
        } else if (y.* > pio4) {
            n += 1;
            @"fn" += 1;
            y.* = x - @"fn" * pio2_1 - @"fn" * pio2_1t;
        }
        return n;
    }
    if (ix >= 0x7f800000) { // x is inf or NaN
        y.* = x - x;
        return 0;
    }
    // scale x into [2^23, 2^24-1]
    sign = ui >> 31 != 0;
    e0 = (ix >> 23) - (0x7f + 23); // e0 = ilogb(|x|)-23, positive
    ui = ix - (e0 << 23);
    tx[0] = @as(f32, @bitCast(ui));
    n = rem_pio2_large(&tx, &ty, @as(i32, @intCast(e0)), 1, 0);
    if (sign) {
        y.* = -ty[0];
        return -n;
    }
    y.* = ty[0];
    return n;
}