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.

acosBinary16

acos.acosBinary16
fn acosBinary16(x: f16) f16

File

lib/std/math/acos.zig:53

Code

fn acosBinary16(x: f16) f16 {
    const pio2: f32 = math.pi / 2.0;

    const hx: u16 = @bitCast(x);
    const ix: u16 = hx & 0x7fff;

    // |x| >= 1 or nan
    if (ix >= 0x3c00) {
        if (ix == 0x3c00) {
            if (hx >> 15 != 0) {
                return @floatCast(2.0 * pio2 + 0x1p-120);
            }
            return 0.0;
        }
        return 0.0 / (x - x);
    }

    const xf: f32 = @floatCast(x);

    // |x| < 0.5
    if (ix < 0x3800) {
        return @floatCast(pio2 - xf * approxBinary16(xf * xf));
    }

    // x < -0.5
    if (hx >> 15 != 0) {
        const z = (1.0 + xf) * 0.5;
        const s = @sqrt(z);
        const w = approxBinary16(z) * s;
        return @floatCast(2.0 * (pio2 - w));
    }

    // x > 0.5
    const z = (1.0 - xf) * 0.5;
    const s = @sqrt(z);
    const w = approxBinary16(z) * s;
    return @floatCast(2.0 * w);
}