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.

cosx

cos.cosx
pub fn cosx(x: f80) callconv(.c) f80

File

lib/compiler_rt/cos.zig:126

Code

pub fn cosx(x: f80) callconv(.c) f80 {
    const se = ld.signExponent(x) & 0x7fff;
    if (se == 0x7fff) {
        return x - x;
    }

    if (@abs(x) < trig.pi_4) {
        if (se < 0x3fff - math.floatMantissaBits(f80)) {
            // raise inexact if x!=0
            return 1.0 + x;
        }
        return trig.cosx(x, 0.0);
    }

    var y: [2]f80 = undefined;
    const n = rem_pio2l(f80, x, &y);
    return switch (n & 3) {
        0 => trig.cosx(y[0], y[1]),
        1 => -trig.sinx(y[0], y[1], 1),
        2 => -trig.cosx(y[0], y[1]),
        else => trig.sinx(y[0], y[1], 1),
    };
}