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.

57 lines
1.5 KiB

25 years ago
  1. #include <cl_number.h>
  2. #include <cl_io.h>
  3. #include <cl_float.h>
  4. #include <cl_float_io.h>
  5. #include <cl_real.h>
  6. #include <cl_random.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <cl_timing.h>
  10. int main (int argc, char * argv[])
  11. {
  12. int repetitions = 1;
  13. if ((argc >= 3) && !strcmp(argv[1],"-r")) {
  14. repetitions = atoi(argv[2]);
  15. argc -= 2; argv += 2;
  16. }
  17. if (argc < 2)
  18. exit(1);
  19. #if 0
  20. uintL len = atoi(argv[1]);
  21. extern cl_LF compute_pi_brent_salamin (uintC len);
  22. extern cl_LF compute_pi_brent_salamin_quartic (uintC len);
  23. extern cl_LF compute_pi_ramanujan_163 (uintC len);
  24. extern cl_LF compute_pi_ramanujan_163_fast (uintC len);
  25. cl_LF p;
  26. { CL_TIMING;
  27. for (int rep = repetitions; rep > 0; rep--)
  28. { p = compute_pi_brent_salamin(len); }
  29. }
  30. // cout << p << endl;
  31. { CL_TIMING;
  32. for (int rep = repetitions; rep > 0; rep--)
  33. { p = compute_pi_brent_salamin_quartic(len); }
  34. }
  35. // cout << p << endl;
  36. { CL_TIMING;
  37. for (int rep = repetitions; rep > 0; rep--)
  38. { p = compute_pi_ramanujan_163(len); }
  39. }
  40. // cout << p << endl;
  41. { CL_TIMING;
  42. for (int rep = repetitions; rep > 0; rep--)
  43. { p = compute_pi_ramanujan_163_fast(len); }
  44. }
  45. // cout << p << endl;
  46. #else
  47. // Here the argument is N *decimal* digits, not N*32 bits!
  48. int n = atoi(argv[1]);
  49. cl_float_format_t prec = cl_float_format(n);
  50. cl_F p;
  51. fprint(cl_stderr, "Computing pi\n");
  52. { CL_TIMING; p = cl_pi(prec); }
  53. fprint(cl_stderr, "Converting pi to decimal\n");
  54. { CL_TIMING; cout << p << endl << endl; }
  55. #endif
  56. }