# How can you calculate catastrophic cancellation error?

I'm trying to follow the wikipedia page about catastrophic cancellation but I've hit something that just doesn't make sense to me. They say that subtraction can amplify existing approximation errors (by making relative error of the difference much larger than relative error of the terms).

But also they say that relative approximation error of the difference $$x-y$$ is $$\delta_{x-y}=|(x\delta_x-y\delta_y)/(x-y)|$$ s.t. $$\forall z, \delta_z:=$$ relative approximation error of z (pic below):

And naively you could say that $$\delta_x=\delta_y=\epsilon$$ (machine epsilon, upper bound of relative approximation error of floats). Which gives: $$\delta_{x-y}=|(x\epsilon-y\epsilon)/(x-y)|=\epsilon|(x-y)/(x-y)|=\epsilon$$. But this contradicts the statement that subtraction can greatly increase the relative error... What am I missing?

The issue they are talking about is if $$x$$ and $$y$$ are close. For example, suppose we know that $$x = y (1 + \epsilon) > y$$ for some small $$\epsilon > 0$$. Then the relative error you wrote can be written as:
$$\left\lvert\frac{x \delta_x - y \delta_y}{x - y}\right\rvert = \left|(\delta_x - \delta_y)/\epsilon +\delta_x\right|$$
As $$\epsilon$$ gets smaller, the error blows up to an arbitrarily large size. The only way this is not true is if in fact $$\delta_x = \delta_y$$ such as in your example, but this is a special case that is not going to be the case in practice.