T z(std::min(std::max(zero, a), r)); a -= z; r -= z;
T za(std::min(std::max(zero, a), r)); a -= za; r -= za;
T progressively_reduce(T& a, T& b, T const& delta){    // Cache T(0) in case it's expensive to construct.    T const zero(0);    // Return value.    T r(delta);    if(zero == r)        {        return r;        }    if(a < zero && r < zero)        {        T z(std::max(a, r));        a -= z;        r -= z;        }    if(b < zero && r < zero)        {        T z(std::max(b, r));        b -= z;        r -= z;        }    if(r < zero)        {        a -= r;        r = zero;        }    else        {        T z(std::min(std::max(zero, a), r));        a -= z;        r -= z;        if(zero < r)            {            T z(std::min(std::max(zero, b), r));            b -= z;            r -= z;            }        }    // In a precise number system, we could now assert:    //   assert(zero <= r);    // But due to the imprecision of floating-point arithmetic, that    // could easily fail. A value close to zero, but of random sign,    // can arise from subtraction of two nearly-identical quantities.    // There are many subtractions in this function, and it's not    // necessarily obvious which one caused such an outcome, so it's    // not trivial to set a reasonable tolerance. Instead, we just let    // negatives arise as they will, and move them into the preferred    // account, explicitly zeroing the return value.    if(r < zero)        {        a -= r;        r = zero;        }    // However, r can still have a tiny positive floating-point value    // when it would be zero in a precise number system. There really    // isn't anything we can do to prevent that.    // Due to the imprecision of floating-point arithmetic, we could    // probably force an assertion like this to fire with legitimate    // input. It would hold, though, in a precise number system.    //    // At top: save original sum just for assertion.    //   T const original_sum(a + b - r);    // Just before exit:    //   assert(materially_equal(original_sum, a + b - r));    return r;}