Z S

Math.Sin Function Not Working for some values of the input argument

Discussion created by Z S on Feb 20, 2011
Latest reply on Feb 21, 2011 by CrasyCat

Hi,

 

I'm using CodeWarrior v 5.9.0 and DSP board MC56F8037

 

 

I'm trying to calculate Sin(arg) and Cos(arg) (to get parameters for FFT analysis)

 

 

for (k = 1; k < transformLength; k++) 
                    {
                  
                  arg = 2*(float)bin*M_PI*(float)k / (float)transformLength;
                  sinPart = sinPart+(inputData[k] * sign * sin(arg);
                  cosPart = cosPart + (inputData[k] * cos(arg));
                 }
The problem is sin(arg) works fine for many values of arg, but for some values of arg it gives TOTALY different output values and destroys all the calculations furhter on.
Example
In CodeWarrior when i debug(having imported Math.h) i get
sin(11.584)=0.968
When i calculate on the calculator (as well as try to calculate in c sharp coded program) It gives
sin(11.584) = -0.828
This is such a huge difference...and it happens for random samples.
For other samples like sin(5.694)=-0.555 both in COdeWarrior and C Shapr the values are the SAME. 
THIS has been really really driving me crazy.
Please, Could you look at this ... Is this a bug???

Outcomes