In C++11 I want to calculate the partial sum of a vector using std::partial_sum.
std::vector<double> vec = {-1.0, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1}; std::partial_sum(vec.begin(), vec.end(), vec.begin()); Unfortunatelly, the last entry of the resulting vector is 1.38778E-16 due to rounding errors of doubles and the fact that 0.1 has no exact presentaion as double.
vec = {-1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 1.38778E-16}; Is there any chance to use the Kahan algorithm in std::partial_sum to reduce rounding errors and get a smaller error - something like
std::partial_sum(vec.begin(), vec.end(), vec.begin(), KahanSum);