I'm trying to get as many correct digits of pi as possible without sacrificing too much speed , so i found a converging series by David Chudnovsky and Gregory Chudnovsky based on Ramanujan's work, when i run it i get up to 3.14159265358973 after 3 the digits are not correct no matter the value of k I also noticed that the counter = 1 , meaning that the loop doesn't work? I would really appreciate the help. My code is:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
long double factorial(unsigned long long int x, unsigned long long int n);
int main()
{
long double big_sum = 0.0;
unsigned long long int k = 0;
unsigned long long int n = 0;
long double numerator;
long double denominator;
long double turm;
turm = (long double)12.0;
cout << "TYPE NUMBER OF DIGITS : ";
cin >> n;
cout << endl;
/* unsigned long long int counter = 0; */
for (k = 0; k < pow(10, 10000); k++)
{
/* counter++; */
cout << setprecision(n) << fixed;
numerator = pow((-1.0), k) * factorial(6 * k, n) * (545140134 * k + 13591409);
denominator = factorial(3 * k, n) * pow(factorial(k, n), 3) * pow(640320, 3 * k + (long
double)(3.0 / 2));
big_sum += turm * (numerator / denominator);
cout << "PI IS = " << pow(big_sum, -1);
/* cout << " counter = " << counter; */
}
return 0;
}
long double factorial(unsigned long long int x, unsigned long long int n)
{
if (x == 0) return 1;
long long int factorial_of_x = 1;
for (unsigned long long int i = 1; i <= x; x++)
{
cout << setprecision(n) << fixed;
factorial_of_x *= i;
}
return factorial_of_x;
}