I've suddenly started getting really weird results with calls to the built-in sin/cos functions in my C++ program.
Everything was working fine, but suddenly objects which rotate go all glitchy and weird. I've tracked down the issue to the following line, which the debugger clearly shows as sin() using single precision floats giving the wrong answer:
float sin_a = sin(angle);
With angle being -0.0017453292, it gives sin_a = 0.096280068. According to my pocket calculator, the correct answer is -0.001745328314. Not only is the result wrongly positive (!!) but it's about 55 times larger!
Even if I just enter directly the following line and compile:
const float weird = sin(-0.78539819);
The debugger shows the result being -0.63439333, versus my calculator saying -0.7071068, still out by the first digit, surely worse than single precision floats can achieve. In this particular program, my co-developer reported precisely the same wrong results on their computer too.
So when anything rotates in my program everything goes all jittery and displays at the wrong angle. Obviously it works fine in a new program, and I have an assembly snippet using the fsincos instruction that doesn't seem to suffer precision problems, and the double precision overloads for sin and cos seem OK. But something must be seriously amiss here. What could cause such serious inaccuracy errors? I've no idea what I might've done to cause this - compiler settings? FPU control flags (I'm not changing any)? Cosmic rays???