I have to change this formula: $$\frac{1-\cos(x)}{x}$$ so that I can avoid the cancellation error. I can do this for 0 but not for $π$. So I get: $$\frac{\sin^2(x)}{x(1+\cos(x))}$$ which for $x$ close to $0$ gets rid of the cancellation error. But I don't know how to fix the error for $x$ close to $π$? I just want to know if I should be using trigonometric identities again? I've tried to use trig identities but nothing works. Any suggestions or hints?
Edit: So for π I meant that sin(π) would be 0 so it wouldn't give me the correct value as (1-cosπ)/π=2/π. The second equation would overall give me 0. That's the error I meant for π. Sorry for the confusion there.
Another possiblity that avoids cancellation error at both places is $$ \frac{2 \sin^2(x/2)}{x} $$