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.

trunc

trunc.trunc
pub fn trunc(x: f64) callconv(.c) f64

File

lib/compiler_rt/trunc.zig:53

Code

pub fn trunc(x: f64) callconv(.c) f64 {
    const u: u64 = @bitCast(x);
    var e = @as(i32, @intCast(((u >> 52) & 0x7FF))) - 0x3FF + 12;
    var m: u64 = undefined;

    if (e >= 52 + 12) {
        return x;
    }
    if (e < 12) {
        e = 1;
    }

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