You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

25 years ago
25 years ago
25 years ago
  1. #include <cln/number.h>
  2. #include <cln/io.h>
  3. #include <cln/float.h>
  4. #include <cln/float_io.h>
  5. #include <cln/real.h>
  6. #include <cln/random.h>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <cln/timing.h>
  10. using namespace std;
  11. using namespace cln;
  12. int main (int argc, char * argv[])
  13. {
  14. int repetitions = 1;
  15. if ((argc >= 3) && !strcmp(argv[1],"-r")) {
  16. repetitions = atoi(argv[2]);
  17. argc -= 2; argv += 2;
  18. }
  19. if (argc < 2)
  20. exit(1);
  21. #if 0
  22. uintL len = atoi(argv[1]);
  23. extern cl_LF compute_pi_brent_salamin (uintC len);
  24. extern cl_LF compute_pi_brent_salamin_quartic (uintC len);
  25. extern cl_LF compute_pi_ramanujan_163 (uintC len);
  26. extern cl_LF compute_pi_ramanujan_163_fast (uintC len);
  27. cl_LF p;
  28. { CL_TIMING;
  29. for (int rep = repetitions; rep > 0; rep--)
  30. { p = compute_pi_brent_salamin(len); }
  31. }
  32. // cout << p << endl;
  33. { CL_TIMING;
  34. for (int rep = repetitions; rep > 0; rep--)
  35. { p = compute_pi_brent_salamin_quartic(len); }
  36. }
  37. // cout << p << endl;
  38. { CL_TIMING;
  39. for (int rep = repetitions; rep > 0; rep--)
  40. { p = compute_pi_ramanujan_163(len); }
  41. }
  42. // cout << p << endl;
  43. { CL_TIMING;
  44. for (int rep = repetitions; rep > 0; rep--)
  45. { p = compute_pi_ramanujan_163_fast(len); }
  46. }
  47. // cout << p << endl;
  48. #else
  49. // Here the argument is N *decimal* digits, not N*32 bits!
  50. int n = atoi(argv[1]);
  51. float_format_t prec = float_format(n);
  52. cl_F p;
  53. cerr << "Computing pi" << endl;
  54. { CL_TIMING; p = pi(prec); }
  55. cerr << "Converting pi to decimal" << endl;
  56. { CL_TIMING; cout << p << endl << endl; }
  57. #endif
  58. }