NOTE: This is for a project I'm working on for fun, NOT production code.

So I'm working on a pet project that involves reading data in from a sensor and summing it up. The values are mostly floating point number mostly in the range (+/-)1 - (+/-)10 and the program is expected to run for at least 2-3 hours, and it collects around 1000 datapoints a second. The goal is to keep an accurate track of their sum, but after 3 hours or so there will be some drift in the calculation (which I would like to minimize).

So my main concern is that since the numbers can be positive and negative there will be too much cancellation that will ruin it, so what I was thinking of trying is to keep 2 kahan summations running, one for positive inputs and one for negative.

So for long runs can I expect this to lead to an increase in precision?

  • $\begingroup$ What do you mean by drift in the calculation? What do you mean by cancellation? If the goal is to compute the sum, then cancellation is part of the definition of what you're trying to compute. Note that after 2-3 hours the maximum value of the sum will still be at most about 10 million or so, which is plenty small enough to fit within the range of any reasonable representation. $\endgroup$ – D.W. Apr 13 '16 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.