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.

add_adjusted128

Compute a+b, with a small tweak: The least significant bit of the result is adjusted into a sticky bit summarizing all the bits that were lost to rounding. This adjustment negates the effects of double rounding when the result is added to another number with a higher exponent. For an explanation of round and sticky bits, see any reference on FPU design, e.g.,

J. Coonen. An Implementation Guide to a Proposed Standard for Floating-Point Arithmetic. Computer, vol. 13, no. 1, Jan 1980.

fma.add_adjusted128
fn add_adjusted128(a: f128, b: f128) f128

File

lib/compiler_rt/fma.zig:252

Code

fn add_adjusted128(a: f128, b: f128) f128 {
    var sum = dd_add128(a, b);
    if (sum.lo != 0) {
        var uhii: u128 = @bitCast(sum.hi);
        if (uhii & 1 == 0) {
            // hibits += copysign(1.0, sum.hi, sum.lo)
            const uloi: u128 = @bitCast(sum.lo);
            uhii = uhii + 1 - ((uhii ^ uloi) >> 126);
            sum.hi = @bitCast(uhii);
        }
    }
    return sum.hi;
}