Like I said, the Taylor series is not going to work very well if you move too far away from 0. In this case, it seems that beyond -pi,pi, it stops working. What you need to do is to bring the angle back within that range, using the identity cos(a + 2*n*pi) = cos(a)
for any integer n (positive or negative). In other words, add or subtract 2*pi
until you get within the range, like this:
while(x > M_PI)
x -= 2 * M_PI;
while(x < -M_PI)
x += 2 * M_PI;
Put that code at the start of your function and it will work. (i.e., 6.28 is going to be near 0).