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.

tanx

trig.tanx
pub fn tanx(x_: f80, y_: f80, odd: i32) f80

File

lib/compiler_rt/trig.zig:368

Code

pub fn tanx(x_: f80, y_: f80, odd: i32) f80 {
    const pio4: f80 = 0.785398163397448309628;
    const pio4lo: f80 = -1.25413940316708300586e-20;

    const T3: f80 = 0.333333333333333333180;
    const T5: f80 = 0.133333333333333372290;
    const T7: f80 = 0.0539682539682504975744;
    const T9: f64 = 0.021869488536312216;
    const T11: f64 = 0.0088632355256619590;
    const T13: f64 = 0.0035921281113786528;
    const T15: f64 = 0.0014558334756312418;
    const T17: f64 = 0.00059003538700862256;
    const T19: f64 = 0.00023907843576635544;
    const T21: f64 = 0.000097154625656538905;
    const T23: f64 = 0.000038440165747303162;
    const T25: f64 = 0.000018082171885432524;
    const T27: f64 = 0.0000024196006108814377;
    const T29: f64 = 0.0000078293456938132840;
    const T31: f64 = -0.0000032609076735050182;
    const T33: f64 = 0.0000023261313142559411;

    var x = x_;
    var y = y_;
    const big = @abs(x) >= 0.67434;
    var sign: i8 = 0;

    if (big) {
        if (x < 0) {
            sign = -1;
            x = -x;
            y = -y;
        }
        x = (pio4 - x) + (pio4lo - y);
        y = 0.0;
    }

    var z = x * x;
    var w = z * z;

    var r = T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 +
        w * (T25 + w * (T29 + w * T33))))));

    var v = z * (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 +
        w * (T27 + w * T31))))));

    var s = z * x;
    r = y + z * (s * (r + v) + y) + T3 * s;
    w = x + r;

    if (big) {
        s = @as(f80, @floatFromInt(1 - 2 * odd));
        v = s - 2.0 * (x + (r - w * w / (w + s)));
        return if (sign == -1) -v else v;
    }

    if (odd == 0) {
        return w;
    }

    // if allow error up to 2 ulp, simply return
    // -1.0 / (x+r) here
    //
    // compute -1.0 / (x+r) accurately
    z = w + 0x1p32 - 0x1p32;
    v = r - (z - x);
    const a = -1.0 / w;
    const t = a + 0x1p32 - 0x1p32;
    s = 1.0 + t * z;
    return t + a * (s + t * v);
}