
2Sum

2Sum is a floating-point algorithm for computing the exact round-off error in a floating-point addition operation.
2Sum and its variant Fast2Sum were first published by Møller in 1965.
Fast2Sum is often used implicitly in other algorithms such as compensated summation algorithms; Kahan's summation algorithm was published first in 1965, and Fast2Sum was later factored out of it by Dekker in 1971 for double-double arithmetic algorithms.
The names "2Sum" and "Fast2Sum" appear to have been applied retroactively by Shewchuk in 1997.
Algorithm.
Given two floating-point numbers formula_1 and formula_2, 2Sum computes the floating-point sum formula_3 and the floating-point error formula_4 so that formula_5.
The error formula_6 is itself a floating-point number.
Provided the floating-point arithmetic is correctly rounded to nearest (with ties resolved any way), as is the default in IEEE 754, and provided the sum does not overflow and, if it underflows, underflows gradually, it can be proven that 
A variant of 2Sum called Fast2Sum uses only three floating-point operations, for floating-point arithmetic in radix 2 or radix 3, under the assumption that the exponent of formula_1 is at least as large as the exponent of formula_2, such as when 
Even if the conditions are not satisfied, 2Sum and Fast2Sum often provide reasonable approximations to the error so that formula_28, which enables algorithms for compensated summation, dot-product, etc., to have low error even if the inputs are not sorted or the rounding mode is unusual.
More complicated variants of 2Sum and Fast2Sum also exist for rounding modes other than round-to-nearest.