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.

acosBinary64

acos.acosBinary64
fn acosBinary64(x: f64) f64

File

lib/std/math/acos.zig:169

Code

fn acosBinary64(x: f64) f64 {
    const pio2_hi: f64 = 1.57079632679489655800e+00;
    const pio2_lo: f64 = 6.12323399573676603587e-17;

    const hx: u32 = @intCast(@as(u64, @bitCast(x)) >> 32);
    const ix: u32 = hx & 0x7fff_ffff;

    // |x| >= 1 or nan
    if (ix >= 0x3ff0_0000) {
        const lx: u32 = @truncate(@as(u64, @bitCast(x)));
        if ((ix - 0x3ff0_0000 | lx) == 0) {
            if (hx >> 31 != 0) {
                return 2.0 * pio2_hi + 0x1.0p-120;
            }
            return 0.0;
        }
        return 0.0 / (x - x);
    }

    // |x| < 0.5
    if (ix < 0x3fe0_0000) {
        // |x| < 2^(-57)
        if (ix <= 0x3c60_0000) {
            return pio2_hi + 0x1.0p-120;
        }
        return pio2_hi - (x - (pio2_lo - x * rationalApproxBinary64(x * x)));
    }

    // x < -0.5
    if (hx >> 31 != 0) {
        const z = (1.0 + x) * 0.5;
        const s = @sqrt(z);
        const w = rationalApproxBinary64(z) * s - pio2_lo;
        return 2 * (pio2_hi - (s + w));
    }

    // x > 0.5
    const z = (1.0 - x) * 0.5;
    const s = @sqrt(z);
    const df: f64 = @bitCast(@as(u64, @bitCast(s)) & 0xffff_ffff_0000_0000);
    const c = (z - df * df) / (s + df);
    const w = rationalApproxBinary64(z) * s + c;
    return 2.0 * (df + w);
}