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.

77 lines
1.9 KiB

25 years ago
25 years ago
  1. #include <LiDIA/bigint.h>
  2. #include <LiDIA/bigfloat.h>
  3. #include <LiDIA/timer.h>
  4. #include <cstdlib>
  5. #include <cstring>
  6. int main (int argc, char * argv[])
  7. {
  8. int digits = 100;
  9. int repetitions = 1;
  10. while (argc >= 3) {
  11. if (!strcmp(argv[1],"-r")) {
  12. repetitions = atoi(argv[2]);
  13. argc -= 2; argv += 2;
  14. continue;
  15. }
  16. if (!strcmp(argv[1],"-n")) {
  17. digits = atoi(argv[2]);
  18. argc -= 2; argv += 2;
  19. continue;
  20. }
  21. break;
  22. }
  23. if (argc < 1)
  24. exit(1);
  25. cerr << "Number of digits: " << digits << "\n";
  26. cerr << "Number of repetitions: " << repetitions << "\n";
  27. bigint pow; power(pow, (bigint)10,digits);
  28. bigfloat::precision(digits*2);
  29. bigint x1; truncate(x1, ((sqrt((bigfloat)5)+1)/2) * (pow*pow));
  30. bigfloat::precision(digits);
  31. bigint x2; truncate(x2, sqrt((bigfloat)3) * pow);
  32. bigint x3 = pow+1;
  33. cerr << "multiplication\n";
  34. { bigint r = x1*x2;
  35. { timer t; t.set_print_mode(0); t.start_timer();
  36. for (int rep = repetitions; rep > 0; rep--)
  37. { bigint r = x1*x2; }
  38. t.stop_timer(); cerr << t << endl;
  39. }
  40. cout << r << endl << endl;
  41. }
  42. cerr << "division\n";
  43. { bigint q; bigint r; div_rem(q,r, x1,x2);
  44. { timer t; t.set_print_mode(0); t.start_timer();
  45. for (int rep = repetitions; rep > 0; rep--)
  46. { bigint q; bigint r; div_rem(q,r, x1,x2); }
  47. t.stop_timer(); cerr << t << endl;
  48. }
  49. cout << q << endl << r << endl << endl;
  50. }
  51. cerr << "isqrt\n";
  52. { bigint r; sqrt(r, x3);
  53. { timer t; t.set_print_mode(0); t.start_timer();
  54. for (int rep = repetitions; rep > 0; rep--)
  55. { bigint r; sqrt(r, x3); }
  56. t.stop_timer(); cerr << t << endl;
  57. }
  58. cout << r << endl << endl;
  59. }
  60. cerr << "gcd\n";
  61. { bigint r = gcd(x1,x2);
  62. { timer t; t.set_print_mode(0); t.start_timer();
  63. for (int rep = repetitions; rep > 0; rep--)
  64. { bigint r = gcd(x1,x2); }
  65. t.stop_timer(); cerr << t << endl;
  66. }
  67. cout << r << endl << endl;
  68. }
  69. }