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?
 A: What I told in my comment works!
$$ c^2 = a^2 + b^2 - 2ab\cos(\gamma) $$
$$c^2 = a^2 + b^2 - 2ab(1-2\sin^2(\gamma/2)) \\ = a^2 + b^2 - 2ab + 4ab\sin^2(\gamma/2) $$
Applying the approximations:
$$c^2 \approx a^2 + a^2 - 2a^2 + 4^2a^2(\gamma^2/4) = a^2\gamma^2$$
So, $$ c \approx a\gamma $$
Now, your condition is such that you have two long sides $a$ and $b$, nearly equal and the opposite side is $c$. This is similar to having a circle of radius $a = b$ and your $c$ being the arc subtended by the angle $\gamma$. Doesn't the result agree with the arc length formula?
A: Perhaps this is helpful:
Insert $2ab-2ab$:
$$c^2 = a^2 - 2ab + b^2 - 2ab(\cos(\gamma)-1) \\
c^2 = (a-b)^2  - 2ab(\cos(\gamma)-1) \\
$$
let $a=b+\delta$ and also expand the taylor-series of the $\cos()$ then
$$c^2 = \delta^2  - 2(b+\delta)b(-\gamma^2/2 + \gamma^4/4!...) \\
c^2 = \delta^2  + 2(b+\delta)b(\gamma^2/2 - \gamma^4/4!...) \\
c^2 =  2b^2(\gamma^2/2 - \gamma^4/4!...) +  \delta(2 b(\gamma^2/2 - \gamma^4/4!...) +\delta)\\
$$
[update] After some more fiddling with this an example might be more instructive. Letting $b=3$, $\delta=1e-6$ and $\gamma=1e-6$ the best approximation is already $c^2 \approx 2b^2 \gamma^2/2 + \delta^2 $ , if we look at the evaluation of the three summands separately, where we evaluate the $1-\cos(\gamma)$ only up to its first term :$$ 2b^2 (\gamma^2/2)=9.0 E-12 \\ 2b\delta (\gamma^2/2)=3.0 E-18 \\ \delta^2= 1.0 E-12$$ and we see, that only the first and the third summand are relevant.
A: 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$.
