Listing 7: Kahan Summation
float fk_add(float * flt_arr) { long i; float sum, correction, corrected_next_term, new_sum; sum = flt_arr[0]; correction = 0.0; for (i = 1; i < ARR_SIZE; i++) { corrected_next_term = flt_arr[i] - correction; new_sum = sum + corrected_next_term; correction = (new_sum - sum) - corrected_next_term; sum = new_sum; } return sum; } /* End of File */