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.

81 lines
1.8 KiB

25 years ago
  1. #include <cl_number.h>
  2. #include <cl_io.h>
  3. #include <cl_integer.h>
  4. #include <cl_integer_io.h>
  5. #include <cl_float.h>
  6. #include <cl_real.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <cl_timing.h>
  10. int main (int argc, char * argv[])
  11. {
  12. int digits = 100;
  13. int repetitions = 1;
  14. while (argc >= 3) {
  15. if (!strcmp(argv[1],"-r")) {
  16. repetitions = atoi(argv[2]);
  17. argc -= 2; argv += 2;
  18. continue;
  19. }
  20. if (!strcmp(argv[1],"-n")) {
  21. digits = atoi(argv[2]);
  22. argc -= 2; argv += 2;
  23. continue;
  24. }
  25. break;
  26. }
  27. if (argc < 1)
  28. exit(1);
  29. fprint(cl_stderr, "Number of digits: ");
  30. fprintdecimal(cl_stderr, digits);
  31. fprint(cl_stderr, "\n");
  32. fprint(cl_stderr, "Number of repetitions: ");
  33. fprintdecimal(cl_stderr, repetitions);
  34. fprint(cl_stderr, "\n");
  35. cl_float_format_t prec = cl_float_format(digits);
  36. cl_float_format_t prec2 = cl_float_format(digits*2);
  37. cl_I pow = expt_pos(10,digits);
  38. cl_I x1 = floor1((sqrt(cl_float(5,prec2))+1)/2 * expt_pos(pow,2));
  39. cl_I x2 = floor1(sqrt(cl_float(3,prec)) * pow);
  40. cl_I x3 = pow+1;
  41. fprint(cl_stderr, "multiplication\n");
  42. { cl_I r = x1*x2;
  43. { CL_TIMING;
  44. for (int rep = repetitions; rep > 0; rep--)
  45. { r = x1*x2; }
  46. }
  47. cout << r << endl << endl;
  48. }
  49. fprint(cl_stderr, "division\n");
  50. { cl_I_div_t qr = floor2(x1,x2);
  51. { CL_TIMING;
  52. for (int rep = repetitions; rep > 0; rep--)
  53. { qr = floor2(x1,x2); }
  54. }
  55. cout << qr.quotient << endl << qr.remainder << endl << endl;
  56. }
  57. fprint(cl_stderr, "isqrt\n");
  58. { cl_I r = isqrt(x3);
  59. { CL_TIMING;
  60. for (int rep = repetitions; rep > 0; rep--)
  61. { r = isqrt(x3); }
  62. }
  63. cout << r << endl << endl;
  64. }
  65. fprint(cl_stderr, "gcd\n");
  66. { cl_I r = gcd(x1,x2);
  67. { CL_TIMING;
  68. for (int rep = repetitions; rep > 0; rep--)
  69. { r = gcd(x1,x2); }
  70. }
  71. cout << r << endl << endl;
  72. }
  73. }