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.
fn add_adjusted128(a: f128, b: f128) f128
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;
}