I've recently made a pi calculator out of a pretty rediculous algorithm (which is incredible accurate by the way). Unfortunately, C++ doubles can only hold 16 digits of it! I know that's plenty enough for any practical applications, but I want more accuracy! (Call me insane). I'm just looking for the simplest way to extend a number past this restriction (maybe with strings/calculating 16 digits at a time and parsing them to a string?). I tried using a float datatype, and while this gave me 2 more digits, it severely lowered the accuracy of the calculation. The actual formula isn't that big of a deal, but I'll show it for the publics amusement.
int iIterations = 0;
double dPi = 0;
double dAccuracy = 0;
cin >> iIterations;
cout << "\n\nCalculating...";
for (double i = 0; i < iIterations; i++)
dPi += (FACT(6 * i) * (13591409 + (545140134 * i))) / (FACT(3 * i) * pow(FACT(i), 3) * (pow(-640320, (3 * i))));
dPi = dPi / (426880 * sqrt(10005));
dPi = 1 / dPi;
cout << "\nPi is: " << setprecision(16) << fixed << dPi;
dAccuracy = ((dPi / PI) * 100);
cout << "\nApproximate Accuracy: " << dAccuracy << "%" ;
return;
Where FACT is a factorial function i made. (is there one include in the cmath library? i dont think there is...)
Feel free to steal the formula since it's been public domain for over 20 years =)