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.

ldexp_cexp32

ldexp.ldexp_cexp32
fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32)

File

Code

fn ldexp_cexp32(z: Complex(f32), expt: i32) Complex(f32) {
    var ex_expt: i32 = undefined;
    const exp_x = frexp_exp32(z.re, &ex_expt);
    const exptf = expt + ex_expt;

    const half_expt1 = @divTrunc(exptf, 2);
    const scale1 = @as(f32, @bitCast((0x7f + half_expt1) << 23));

    const half_expt2 = exptf - half_expt1;
    const scale2 = @as(f32, @bitCast((0x7f + half_expt2) << 23));

    return Complex(f32).init(
        @cos(z.im) * exp_x * scale1 * scale2,
        @sin(z.im) * exp_x * scale1 * scale2,
    );
}