I've been googling around for a solution to this problem. I've seen a number of ways to calculate atan(theta) for any -1 <= theta <= 1, but I am not sure what to do when theta is bigger or smaller than those bounds.
I assume I need to add or subtract multiples of pi to offset it? Is this line of thinking correct?
Currently I have:
double my_atan(double x)
{
return x - (x*x*x)/3 + (x*x*x*x*x)/5;
}
Which is using the taylor series.
And for the following code,
int x;
for (x=0; x<M_PI*2; x++)
{
printf("Actual: %f\n", atan(x));
printf("Approx: %f\n", my_atan(x));
printf("\n");
}
It quickly loses control (as expected, as it's out of range):
Actual: 0.000000
Approx: 0.000000
Actual: 0.785398
Approx: 0.866667
Actual: 1.107149
Approx: 5.733333
Actual: 1.249046
Approx: 42.600000
Actual: 1.325818
Approx: 187.466667
Actual: 1.373401
Approx: 588.333333
Actual: 1.405648
Approx: 1489.200000
Not pictured here, but the output is fairly accurate when theta is within the appropriate range.
So my question is what steps exactly need to be taken to the my_tan function to allow it to support wider bounds?
Been staring at this for a while and so any guidance that can be offered would be much appreciated