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.

tanq

trig.tanq
pub fn tanq(x_: f128, y_: f128, odd: i32) f128

File

lib/compiler_rt/trig.zig:439

Code

pub fn tanq(x_: f128, y_: f128, odd: i32) f128 {
    const pio4: f128 = 0x1.921fb54442d18469898cc51701b8p-1;
    const pio4lo: f128 = 0x1.cd129024e088a67cc74020bbea60p-116;

    const T3: f128 = 0x1.5555555555555555555555555553p-2;
    const T5: f128 = 0x1.1111111111111111111111111eb5p-3;
    const T7: f128 = 0x1.ba1ba1ba1ba1ba1ba1ba1b694cd6p-5;
    const T9: f128 = 0x1.664f4882c10f9f32d6bbe09d8bcdp-6;
    const T11: f128 = 0x1.226e355e6c23c8f5b4f5762322eep-7;
    const T13: f128 = 0x1.d6d3d0e157ddfb5fed8e84e27b37p-9;
    const T15: f128 = 0x1.7da36452b75e2b5fce9ee7c2c92ep-10;
    const T17: f128 = 0x1.355824803674477dfcf726649efep-11;
    const T19: f128 = 0x1.f57d7734d1656e0aceb716f614c2p-13;
    const T21: f128 = 0x1.967e18afcb180ed942dfdc518d6cp-14;
    const T23: f128 = 0x1.497d8eea21e95bc7e2aa79b9f2cdp-15;
    const T25: f128 = 0x1.0b132d39f055c81be49eff7afd50p-16;
    const T27: f128 = 0x1.b0f72d33eff7bfa2fbc1059d90b6p-18;
    const T29: f128 = 0x1.5ef2daf21d1113df38d0fbc00267p-19;
    const T31: f128 = 0x1.1c77d6eac0234988cdaa04c96626p-20;
    const T33: f128 = 0x1.cd2a5a292b180e0bdd701057dfe3p-22;
    const T35: f128 = 0x1.75c7357d0298c01a31d0a6f7d518p-23;
    const T37: f128 = 0x1.2f3190f4718a9a520f98f50081fcp-24;
    const T39: f64 = 0.000000028443389121318352;
    const T41: f64 = 0.000000011981013102001973;
    const T43: f64 = 0.0000000038303578044958070;
    const T45: f64 = 0.0000000034664378216909893;
    const T47: f64 = -0.0000000015090641701997785;
    const T49: f64 = 0.0000000029449552300483952;
    const T51: f64 = -0.0000000022006995706097711;
    const T53: f64 = 0.0000000015468200913196612;
    const T55: f64 = -0.00000000061311613386849674;
    const T57: f64 = 1.4912469681508012e-10;

    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 + w * (T37 + w * (T41 +
            w * (T45 + w * (T49 + w * (T53 + w * T57))))))))))));

    var v = z * (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 +
        w * (T27 + w * (T31 + w * (T35 + w * (T39 + w * (T43 +
            w * (T47 + w * (T51 + w * T55))))))))))));

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

    if (big) {
        s = @as(f128, @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);
}