Problem I am solving a fibonacci problem where user enters any index and I have to get the fibonacci number of that index. My code is working just fine for small number 0-80 but after that the code does not output the exact fibonacci number
Example: The fibonacci of 100 will be 354224848179261915075 and I am getting 354224848179261800448. I used bigint in c++ to store the answer. Precision is important because I just need last 5 bits of my answer.
Here is my code
int n;
cin>>n;
setprecision(18);
double term1=(1+sqrt(5))/2;
double term2=(1-sqrt(5))/2;
double ans = (1/sqrt(5))*(pow(term1, n)-pow(term2, n));
std::cout << std::fixed << ans2<<endl;
Sorry I'm not good in English.