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.

asinBinary32

asin.asinBinary32
fn asinBinary32(x: f32) f32

File

lib/std/math/asin.zig:98

Code

fn asinBinary32(x: f32) f32 {
    const pio2: f64 = 1.570796326794896558e+00;

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

    // |x| >= 1
    if (ix >= 0x3f80_0000) {
        // |x| == 1
        if (ix == 0x3f80_0000) {
            // asin(+-1) = +-pi/2 with inexact
            return @floatCast(@as(f64, @floatCast(x)) * pio2 + 0x1.0p-120);
        }
        // asin(|x| > 1) is nan
        return 0.0 / (x - x);
    }

    // |x| < 0.5
    if (ix < 0x3f00_0000) {
        // 0x1p-126 <= |x| < 0x1p-12
        if (ix < 0x3980_0000 and ix >= 0x0080_0000) {
            return x;
        }
        return x + x * rationalApproxBinary32(x * x);
    }

    // 1 > |x| >= 0.5
    const z = (1.0 - @abs(x)) * 0.5;
    const s: f64 = @floatCast(@sqrt(z));
    const x_local: f32 = @floatCast(pio2 - 2.0 * (s + s * @as(f64, @floatCast(rationalApproxBinary32(z)))));
    return if (hx >> 31 != 0) -x_local else x_local;
}