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.

80 lines
1.7 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. #include <cln/number.h>
  2. #include <cln/io.h>
  3. #include <cln/integer.h>
  4. #include <cln/integer_io.h>
  5. #include <cln/float.h>
  6. #include <cln/real.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 digits = 100;
  15. int repetitions = 1;
  16. while (argc >= 3) {
  17. if (!strcmp(argv[1],"-r")) {
  18. repetitions = atoi(argv[2]);
  19. argc -= 2; argv += 2;
  20. continue;
  21. }
  22. if (!strcmp(argv[1],"-n")) {
  23. digits = atoi(argv[2]);
  24. argc -= 2; argv += 2;
  25. continue;
  26. }
  27. break;
  28. }
  29. if (argc < 1)
  30. exit(1);
  31. cerr << "Number of digits: " << digits << endl;
  32. cerr << "Number of repetitions: " << repetitions << endl;
  33. float_format_t prec = float_format(digits);
  34. float_format_t prec2 = float_format(digits*2);
  35. cl_I pow = expt_pos(10,digits);
  36. cl_I x1 = floor1((sqrt(cl_float(5,prec2))+1)/2 * expt_pos(pow,2));
  37. cl_I x2 = floor1(sqrt(cl_float(3,prec)) * pow);
  38. cl_I x3 = pow+1;
  39. cerr << "multiplication" << endl;
  40. { cl_I r = x1*x2;
  41. { CL_TIMING;
  42. for (int rep = repetitions; rep > 0; rep--)
  43. { r = x1*x2; }
  44. }
  45. cout << r << endl << endl;
  46. }
  47. cerr << "division" << endl;
  48. { cl_I_div_t qr = floor2(x1,x2);
  49. { CL_TIMING;
  50. for (int rep = repetitions; rep > 0; rep--)
  51. { qr = floor2(x1,x2); }
  52. }
  53. cout << qr.quotient << endl << qr.remainder << endl << endl;
  54. }
  55. cerr << "isqrt" << endl;
  56. { cl_I r = isqrt(x3);
  57. { CL_TIMING;
  58. for (int rep = repetitions; rep > 0; rep--)
  59. { r = isqrt(x3); }
  60. }
  61. cout << r << endl << endl;
  62. }
  63. cerr << "gcd" << endl;
  64. { cl_I r = gcd(x1,x2);
  65. { CL_TIMING;
  66. for (int rep = repetitions; rep > 0; rep--)
  67. { r = gcd(x1,x2); }
  68. }
  69. cout << r << endl << endl;
  70. }
  71. }