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.

asinBinary64

asin.asinBinary64
fn asinBinary64(x: f64) f64

File

lib/std/math/asin.zig:148

Code

fn asinBinary64(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 = hx & 0x7fffffff;

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

    // |x| < 0.5
    if (ix < 0x3fe0_0000) {
        // if 0x1p-1022 <= |x| < 0x1p-26 avoid raising overflow
        if (ix < 0x3e50_0000 and ix >= 0x0010_0000) {
            return x;
        }
        return x + x * rationalApproxBinary64(x * x);
    }

    // 1 > |x| >= 0.5
    const z = (1.0 - @abs(x)) * 0.5;
    const s = @sqrt(z);
    const r = rationalApproxBinary64(z);
    // |x| > 0.975
    if (ix >= 0x3fef_3333) {
        const x_local = pio2_hi - (2 * (s + s * r) - pio2_lo);
        return if (hx >> 31 != 0) -x_local else x_local;
    }
    // f+c = sqrt(z)
    const hs: u64 = @bitCast(s);
    const f: f64 = @bitCast(hs & 0xffff_ffff_0000_0000);
    const c: f64 = (z - f * f) / (s + f);
    const x_local = 0.5 * pio2_hi - (2.0 * s * r - (pio2_lo - 2.0 * c) - (0.5 * pio2_hi - 2.0 * f));
    return if (hx >> 31 != 0) -x_local else x_local;
}