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.

proc2

log_f128.proc2
pub fn proc2(comptime p: Proc2, x: f128) f128

File

lib/compiler_rt/log_f128.zig:110

Code

pub fn proc2(comptime p: Proc2, x: f128) f128 {
    std.debug.assert(Proc2.lo < x and x < Proc2.hi);

    const f = x - 1.0;
    const g = 1 / (2 + f);
    const u = 2 * f * g;
    const v = u * u;
    const uv = u * v;
    const v64: f64 = @floatCast(v);

    const p17 = p.poly.b17 + v64 * p.poly.b19;
    const p15 = p.poly.b15 + v64 * p17;
    const p13 = p.poly.b13 + v * p15;
    const p11 = p.poly.b11 + v * p13;
    const p9 = p.poly.b9 + v * p11;
    const p7 = p.poly.b7 + v * p9;
    const p5 = p.poly.b5 + v * p7;

    const q_hi = uv * p.poly.b3;
    const q_lo = uv * v * p5;

    const f_hi: f128 = @as(f64, @floatCast(f));
    const f_lo = f - f_hi;

    const u_hi: f128 = @as(f64, @floatCast(u));
    const u_lo = ((2 * (f - u_hi) - u_hi * f_hi) - u_hi * f_lo) * g;

    if (comptime p.poly.b1_hi == 1.0 and p.poly.b1_lo == 0.0)
        return u_hi + (u_lo + (q_hi + q_lo));

    // t = u * p.poly.b1
    const t_hi = u_hi * p.poly.b1_hi;
    const t_lo = u_lo * p.poly.b1_hi + u * p.poly.b1_lo;

    // y = t + q
    const y_hi = t_hi + q_hi;
    const y_lo = t_lo + (t_hi - y_hi + q_hi) + q_lo;

    return y_hi + y_lo;
}