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.

truncf

trunc.truncf
pub fn truncf(x: f32) callconv(.c) f32

File

lib/compiler_rt/trunc.zig:32

Code

pub fn truncf(x: f32) callconv(.c) f32 {
    const u: u32 = @bitCast(x);
    var e = @as(i32, @intCast(((u >> 23) & 0xFF))) - 0x7F + 9;
    var m: u32 = undefined;

    if (e >= 23 + 9) {
        return x;
    }
    if (e < 9) {
        e = 1;
    }

    m = @as(u32, math.maxInt(u32)) >> @intCast(e);
    if (u & m == 0) {
        return x;
    } else {
        if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120);
        return @bitCast(u & ~m);
    }
}