Avoid cumulative rounding errors when calculating a result to a specific number of significant figures

rounding errorsignificant figures

I have two operands and I want to calculate the result of an arithmetic operation (add, sub, mul, div, pow, sqrt, ln…) to S significant figures. How many significant figures do I need in the operands to achieve this result without rounding of the least significant digit?

For example, let's consider a context of "always accurate to 2 significant figures".

0.123 * 0.456 = 0.056088, rounded to 0.056 (2 s.f).

If we keep using that result for future calculations within this context, we'll get rounding errors because we've lost data along the way. My question is: could I avoid rounding errors in the current context by calculating the result to precision + x?

For example, with the same context (always accurate to 2 s.f), we can calculate to 4 s.f:

0.123 * 0.456 = 0.056088, rounded to 0.05609. Could I now use this result without losing accuracy along the way? Or would the rounding inevitable cause inaccuracy?

Best Answer

There is no answer. Subtraction makes it easy to see. If you want to subtract $1.0000000-0.9999999$ to two significant figures you need to carry a lot of figures. For multiplication and division the problem comes from the fact that a chance of $1$ in the third place is a chance of $1\%$ in $1.00$ but $0.1\%$ in $9.99$. The fractional error is maintained with multiplication and division. Functions like pow and log are also problematic.

Added: even worse, $\frac 1x-\frac 2{x+1}+\frac 1{x+2}$ is about $\frac 2{x^3}$ for large $x$. If $x \approx 1000$ you need to keep $11$ places to get $2$ places out at the end. We can keep going like this.

Related Question