I've just come across a peculiar result from a maths equation which makes absolutely no sense (to me).
Background is a program I'm writting to solve triangles. Most things are working as expected but since there are potentially an infinite number of potential 'Triangles' and I'm allowing only 3 of the 6 values to be specified, I've found that some data is 'special' inasmuch as it needs alternative code.
The particular issue is that a formula when used as a single line returns zero but when evaluated as separate functions returns the correct value.
Knowing two sides (B & C) and the enclosed angle (alpha), the length of the unknown side (A) is given by :
A := Sqrt( B
2 + C2 - (2*B*C * Cos(alpha)))
In the case that B=3, C=6 and Alpha = 60° - Laz returns ZERO from this formula but if I code :
begin
A := b*b + c*c;
A := A - (2*b*c * cos_a);
A := Sqrt(A);
end
'A' is returned correctly!
I cannot fathom this so I'd appreciate any thoughts as to what I'm doing wrong (with the one-line code) ?