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.

acosExtended80

acos.acosExtended80
fn acosExtended80(x: f80) f80

File

lib/std/math/acos.zig:233

Code

fn acosExtended80(x: f80) f80 {
    const pio2_hi: f80 = 1.57079632679489661926;
    const pio2_lo: f80 = -2.50827880633416601173e-20;

    const hx: u80 = @bitCast(x);
    const se: u16 = @truncate(hx >> 64);
    const e = se & 0x7fff;

    // |x| >= 1 or nan
    if (e >= 0x3fff) {
        if (x == 1.0) {
            return 0.0;
        }
        if (x == -1.0) {
            return 2.0 * pio2_hi + 0x1p-120;
        }
        return 0.0 / (x - x);
    }
    // |x| < 0.5
    if (e < 0x3fff - 1) {
        if (e < 0x3fff - math.floatFractionalBits(f80)) {
            return pio2_hi + 0x1p-120;
        }
        return pio2_hi - (rationalApproxExtended80(x * x) * x - pio2_lo + x);
    }
    // x < -0.5
    if (se >> 15 != 0) {
        const z = (1 + x) * 0.5;
        const s = @sqrt(z);
        return 2.0 * (pio2_hi - (rationalApproxExtended80(z) * s - pio2_lo + s));
    }
    // x > 0.5
    const z = (1.0 - x) * 0.5;
    const s = @sqrt(z);
    const hs: u80 = @bitCast(s);
    const f: f80 = @bitCast(hs & 0xffff_ffff_ffff_0000_0000);
    const c = (z - f * f) / (s + f);
    return 2.0 * (rationalApproxExtended80(z) * s + c + f);
}