The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information.... |
Home MathPack Math1 Class TKahanSum TKahanSum | |||||||
See also: Add, Reset, Sum | |||||||
TKahanSum |
|||||||
When adding a large number of floating point numbers the finite precision of these values may result in considerable round-off errors. In particular the "normal" summation of N numbers shows an error which is proportional to N. The Kahan summation algorithm significantly reduces the numerical error of the sum, leading in effect to an error which only depends on the floating point precision and which is independent of N. The Kahan algorithm (also called "compensation algorithm") is based on a separate running compensation variable which accumulates small errors. The algorithm is attributed to William Kahan.1) The general approach of calculating an error-compensated sum is first to use the Reset method to clear the sum, then add all terms to be added by the method Add. The error-compensated sum can be obtained by reading the public variable Sum.
|