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.
Zig › compiler_rt/ › round.zig › round
round
round.round
pub fn round (x_ : f64 ) callconv (.c ) f64
File
Code
pub fn round (x_ : f64 ) callconv (.c ) f64 {
const f64_toint = 1.0 / math .floatEps (f64 );
var x = x_ ;
const u : u64 = @bitCast (x );
const e = (u >> 52 ) & 0x7FF ;
var y : f64 = undefined ;
if (e >= 0x3FF + 52 ) {
return x ;
}
if (u >> 63 != 0 ) {
x = -x ;
}
if (e < 0x3ff - 1 ) {
if (compiler_rt .want_float_exceptions ) mem .doNotOptimizeAway (x + f64_toint );
return 0 * @as (f64 , @bitCast (u ));
}
y = x + f64_toint - f64_toint - x ;
if (y > 0.5 ) {
y = y + x - 1 ;
} else if (y <= -0.5 ) {
y = y + x + 1 ;
} else {
y = y + x ;
}
if (u >> 63 != 0 ) {
return -y ;
} else {
return y ;
}
}