Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
arm_cos_f32 with around -pi/2 #267
I found a result value from arm_cos_f32 is wrong in a particular situation.
The problem occurred when I call the function with a parameter around -pi/2.
I think this problem is related to a past bug of arm_sin_f32.
I think added lines to fix this bug are here.
Although the implementation of arm_cos_f32 is very similar to arm_sin_f32 and a same bug can occur in arm_sin_f32 cos, changes have been made only for arm_sin_f32.
Hi @JonatanAntoni ,
This means as follows.
uint32_t x_bin = 0xbfc90fdc; float *x = (float*)&x_bin; // *x is -pi/2 in float float cos_result = arm_cos_f32(*x);
This cos_result should be about 0.0 (=cos(-pi/2)), but this is over 1.0.
You are true the comments in the code (not exactly reproduced in the API) are not as strong as it should (https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/DSP/Source/FastMathFunctions/arm_cos_f32.c#L80 : "Scale the input to [0 1] range from [0 2*PI] " without telling to avoid data out of this range. We will correct this quickly.
I think this is exactly right. The special case implemented in arm_sin_f32 should be carried over to arm_cos_f32.
We can see that in the top of the test data there is already a special entry of -1.5E-07, seemingly to verify the arm_sin_f32. We should similarly add -1.5707965 that @idt12312 identified, to check correct operation of arm_cos_f32.