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.

acosBinary32

acos.acosBinary32
fn acosBinary32(x: f32) f32

File

lib/std/math/acos.zig:107

Code

fn acosBinary32(x: f32) f32 {
    const pio2_hi: f32 = 1.5707962513e+00;
    const pio2_lo: f32 = 7.5497894159e-08;

    const hx: u32 = @bitCast(x);
    const ix: u32 = hx & 0x7fff_ffff;

    // |x| >= 1 or nan
    if (ix >= 0x3f800000) {
        if (ix == 0x3f800000) {
            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 < 0x3f00_0000) {
        // |x| < 2^(-26)
        if (ix <= 0x3280_0000) {
            return pio2_hi + 0x1.0p-120;
        }
        return pio2_hi - (x - (pio2_lo - x * rationalApproxBinary32(x * x)));
    }

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

    // x > 0.5
    const z = (1.0 - x) * 0.5;
    const s = @sqrt(z);
    const hs: u32 = @bitCast(s);
    const df: f32 = @bitCast(hs & 0xffff_f000);
    const c = (z - df * df) / (s + df);
    const w = rationalApproxBinary32(z) * s + c;
    return 2.0 * (df + w);
}