I know that there are more elegant solutions to this problem than what I'm using, but I've been asked to compose this for a class, not using the pow() function, and frankly, I don't want to use codes that are beyond the scope of the class so far. This code should use the first 10 x terms of a Taylor series:
cos(x) = 1 - x^2/2! + x^4/4! - x^6/6! ...
It's perfectly functional for its purpose, but if I set i equal to 34 or above (meaning, expanding the code out to x^34/34!), it begins to return 'nan' for the function, and I was wondering if someone could explain why.
Thank you very much! Not really necessary for my purposes here, but I'd like to know what's going one. It seems like I should be able to keep increasing this value, converging on the value given by the cos() function in cmath.
# include <iostream>
# include <cmath>
using namespace std;