Last active
August 11, 2019 20:09
-
-
Save shouth/d2c96b11030f4a88313b6882afb00662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cmath> | |
#include<iomanip> | |
#include<iostream> | |
#include<gmpxx.h> | |
int main() { | |
unsigned digit = 10000; | |
mpf_set_default_prec((digit + 1) * log2(10)); | |
mpf_class pi = 0; | |
unsigned m = digit / 4; | |
mpz_class p5 = 5; | |
for (unsigned n = 0; n < 3 * m + 2; n++) { | |
pi += (n % 2 == 0 ? 16_mpf : -16_mpf) / ((2 * n + 1) * p5); | |
p5 *= 25; | |
} | |
mpz_class p239 = 239; | |
for (unsigned n = 0; n < m; n++) { | |
pi += (n % 2 == 1 ? 4_mpf : -4_mpf) / ((2 * n + 1) * p239); | |
p239 *= 57121; | |
} | |
std::cout << std::fixed << std::setprecision(digit + 1) << pi << std::endl; | |
} |
Author
shouth
commented
Jun 24, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment