/* test_mpf_pi precision(10-) output-flag(0-1) Compile: gcc -I/usr/local/include -L/usr/local/lib -Wall -O3 -o test_mpf_pi test_mpf_pi.c mpf_pi.c -lgmp */ #include #include #include #include #define LOG_2_10 3.32192809488736234787031942949 void mpf_pi (mpf_t rop); int main (int argc, char *argv[]) { int error = 0, output = 1; unsigned long int prec10 = 100; mpf_t pi; struct tms t_buf; clock_t start, stop; switch (argc) { case 3: error |= sscanf (argv[2], "%d", &output) != 1; case 2: error |= sscanf (argv[1], "%lu", &prec10) != 1; if (prec10 < 10) { prec10 = 10; } break; default: error = 1; } if (error) { printf ("usage: %s precision(10-) output-flag(0-1)\n", argv[0]); return error; } mpf_init2 (pi, (int) ((double) (2 + prec10) * LOG_2_10) + 1); stop = times (&t_buf); while ((start = times (&t_buf)) == stop); mpf_pi (pi); stop = times (&t_buf); printf ("%.3f sec.\n", (double) (stop - start) / (double) sysconf (_SC_CLK_TCK)); if (output) { gmp_printf ("%.*Ff\n", prec10, pi); stop = times (&t_buf); printf ("%.3f sec.\n", (double) (stop - start) / (double) sysconf (_SC_CLK_TCK)); } mpf_clear (pi); return 0; }