Artificial intelligent assistant

Law of Cosines for very acute angles, round-off error We have $$ c^2 = a^2 + b^2 - 2ab\cos(\gamma) $$ If $a \approx b$ and $\gamma$ is very small, then the above formulation has quite a bit of round-off error. Is there a better formulation that would help to reduce some of the error?

Using the algebra from the other answer, it seems like a better approximation would be: $$ c^2 = (a - b)^2 + 4ab\sin^2(\gamma/2) $$ You'll still get some subtractive cancellation when computing $a-b$, but it's not as bad as the original formula.

Also, when $\gamma$ is small, calculating $\sin\gamma$ accurately is easier than calculating $\cos\gamma$.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy a0902136578f35b6b75b0f7da9585c86