/* mpfr_pi.c : This program is treated as public domain software */ #include #include #include #include "mpfr.h" void usage(const char *progname) { printf("$ %s [# of decimal digit for PI]\n", progname); } int main(int argc, char *argv[]) { long int digit, bit; clock_t begin, end; mpfr_t pi; if(argc <= 1) { usage(argv[0]); return 0; } /* # of decimal digit to # of bits */ bit = (long int)ceil((double)atoi(argv[1]) / log10(2.0)); printf("# of decimal digits: %d\n", atoi(argv[1])); printf("# of bits : %d\n", bit); /* Initialize */ mpfr_init2(pi, bit); /* Get pi */ begin = clock(); mpfr_const_pi(pi, GMP_RNDN); end = clock(); /* Output */ printf("Time : %6.3f\n", (double)(end - begin) / CLOCKS_PER_SEC); /* Remove comment if you want to output pi */ //mpfr_out_str(stdout, 10, 0, pi, GMP_RNDN); printf("\n"); /* Clear */ mpfr_clear(pi); return 0; }