This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi all,
I am using the TMS320F280049 series for my application. I have used the sin function by assigning it to a double and provided it parameter also as a double variable. When I pass PI i.e 180 degrees in the sine function, it returns a negative value like -4.37139533e-08. Ideally it should return 0. I have included math.h as well. How do I rectify this issue?
Code:
double number;
double sine_of_number;
number = M_PI;
sine_of_number = sin(number);
Regards,
Pranav
Pranav,
Which library are you using for the sin function? Also , let us know the C2000Ware version that you are using.
Best Regards
Siddharth
Pranav,
So, you are not using any libraries within C2000Ware for computing the sin. You are using the compiler provided header file "math.h".
Is this correct? If so, let us know the compiler version that you are using,
Best Regards
Siddharth
Yes, I am not using any library within C2000Ware for computing sine. I am using the compiler provided header file. The compiler version I am using is TI v21.6.0.LTS Also what library with C2000Ware do you suggest to use for sine computation?
Ideally it should return 0
Ideally it should never be zero because π is irrational. Having said that, the value of M_PI is smaller than π because it is truncated so sin(M_PI) should be positive at least where you are seeing a negative value. The conclusion is that there must be some rounding up of M_PI somewhere to approximately 3.1415927.
What are your compiler settings for --float_support and --tmu_support?
Hmm, strange. I think there's two possibilites:
1) Your doubles are actually floats.
2) You might have the following setting:
When I enable this setting I can (almost) replicate your issue:
So M_PI (3.14159265358979323846) is being modified to single precision (3.1415927410125732) when assigned to number.
Pranav,
You can try out with the option suggested by Kier.
Best Regards
Siddharth
Hi,
I don't have the option to select/deselect that setting for treating floating-point constants.
I think that zipping up and sharing a project that demonstrates the issue might be the next step.
Pranav ,
You can share the zip file of your project.
There are few examples in C2000Ware C:\ti\c2000\C2000Ware_4_01_00_00\libraries\math\FPUfastRTS\c28\examples that you can use for sin computation.
Best Regards
Siddharth
I have used the sin function by assigning it to a double and provided it parameter also as a double variable.
Your sample project does not contain the code in your initial post. Nonetheless I found a use of sin() in ADC_A1_ISR.
As we can see, gf16Sine is a float. Why do you expect this to have double precision?
Furthermore gf16Sine is not in your map file. It looks like your source has been modified after the last successful build.