# Numerical Analysis/Loss of Significance

Loss of significance occurs in numerical calculations when too many significant digits cancel. As a result of the floating point arithmetic used by computers, when a number is subtracted from another number that is almost exactly the same, catastrophic cancellation may occur and an erroneous value returned. As an example, consider the behavior of

${\displaystyle f(x)={\sqrt {x^{2}+1}}-1}$

as x approaches 0. Evaluating this function at ${\displaystyle x=1.89\times 10^{-9}}$ using Matlab incorrectly returns the answer 0, which shows that too many significant digits have cancelled.

If x and y are positive, normalized floating point binary numbers such that ${\displaystyle x>y}$ and

${\displaystyle 2^{-q}\leq 1-{y \over x}\leq 2^{-p}\,,}$

(bound)

then at most ${\displaystyle q}$ and at least ${\displaystyle p}$ significant binary bits are lost in the subtraction ${\displaystyle x-y}$.

On this page we will consider several exercises/examples of using this formula and show how sometimes we can rearrange the calculation to reduce loss of significance. Please try the exercise yourself before revealing the solution.

## Exercises

### Exercise 1

Use ${\displaystyle 2^{-q}\leq 1-{y \over x}\leq 2^{-p}}$ to find a lower bound on the input x if one desires to lose no more than 1 significant binary bit in the calculation of ${\displaystyle f(x)={\sqrt {x^{2}+1}}-1}$.

### Exercise 2

Use ${\displaystyle 2^{-q}\leq 1-{y \over x}\leq 2^{-p}}$ to find a lower bound on the input x if one desires to lose at most 3 significant binary bits in the calculation of ${\displaystyle f(x)={\sqrt {x^{2}+1}}-1}$.

### Exercise 3

Consider

${\displaystyle f(x)={\sqrt {x^{2}+1}}-x\,.}$

As x gets very large, loss of significance can occur. What is the bound on x if we want to lose no more than one binary digit?

### Exercise 4

Now consider the function

${\displaystyle f(x)=\log(x+1)-\log(x)\,.}$

For large values of x, loss of significance may occur.

Use (bound ) to find a bound on the input so that at most 1 significant binary bit will be lost in the calculation.

### Exercise 5

${\displaystyle f'(x)\approx {f(x+h)-f(x) \over h}}$

is often used to approximate derivatives. w:Truncation error can be reduced by decreasing "h", the step size, but if h becomes too small, loss of significance can become a factor. For ${\displaystyle {f(x+h)-f(x) \over h}}$, find a bound on h such that at most 1 binary bit will be lost in the calculation.

### Exercise 6

For ${\displaystyle {f(x+h)-f(x) \over h}}$, find a bound on h such that at most 1 binary bit will be lost in the calculation, if ${\displaystyle f(x)=x^{2}}$.

### Exercise 7

Rewrite ${\displaystyle f(x)={\sqrt {x^{2}+1}}-1}$ so that there is no loss of significance, then evaluate it at ${\displaystyle x=1.89\times 10^{-9}}$.

### Exercise 8

Rewrite ${\displaystyle f(x)=\log(x+1)-\log(x)}$ so that loss of significance will be minimized.

### Exercise 9

For very small values of x, loss of significance can occur in ${\displaystyle f(x)={1-x \over 1+x}-{1 \over 3x+1}}$. Rewrite this function in a way that will minimize loss of significance.

### Exercise 10

As x gets close to zero, loss of significance can occur in ${\displaystyle f(x)={\frac {1-\cos(x)}{\sin(x)}}}$. Rewrite this function in a way that will minimize loss of significance.