Skip to main content

two_sum

pub fn two_sum(a: f64, b: f64) -> (f64, f64)
Expand description

Error-free addition: a + b = s + e where s = round(a + b) and e is the exact rounding error.

Knuth’s algorithm (TAOCP Vol. 2, §4.2.2, Theorem B). Works for any a, b regardless of relative magnitude. Six floating-point operations.