I understand that when subtracting two values that are nearly identical there is a loss of significance. Aside from this however I'm not quite sure how to tell what results in the next largest loss of precision.
For example, here is a problem in my textbook:
f(x) = tan(x) − sin(x) when x ~ 0
What is the best and worst algorithm for evaluating this out of these three choices:
(a) (1/ cos(x) − 1) sin(x),
(b) (x^3)/2
(c) tan(x)*(sin(x)^2)/(cos(x) + 1).
I understand that when x is close to zero, tan(x) and sin(x) are nearly the same. I don't understand how or why any of these algorithms are better or worse for solving the problem.
In my opinion it seems as though option a will always give the most loss of significance, simply because when x is a small enough number you can have a roundoff error that leads to a dividing by 0 error.
Meanwhile I can't tell what would make for the best algorithm for avoiding loss of significance. Option b and c seem nearly identical to me in terms of loss of significance. How can I know which algorithm gives the better results and know for the future?