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.

202 lines
4.7 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 (except for pi,euler,e): " << repetitions << "\n";
  27. bigfloat::precision(digits);
  28. bigfloat x1 = sqrt((bigfloat)2);
  29. bigfloat x2 = sqrt((bigfloat)3);
  30. bigfloat x3 = log((bigfloat)2);
  31. cerr << "multiplication\n";
  32. { bigfloat r = x1*x2;
  33. { timer t; t.set_print_mode(0); t.start_timer();
  34. for (int rep = repetitions; rep > 0; rep--)
  35. { r = x1*x2; }
  36. t.stop_timer(); cerr << t << endl;
  37. }
  38. cout << r << endl << endl;
  39. }
  40. cerr << "sqrt\n";
  41. { bigfloat r = sqrt(x3);
  42. { timer t; t.set_print_mode(0); t.start_timer();
  43. for (int rep = repetitions; rep > 0; rep--)
  44. { r = sqrt(x3); }
  45. t.stop_timer(); cerr << t << endl;
  46. }
  47. cout << r << endl << endl;
  48. }
  49. cerr << "pi\n";
  50. { bigfloat r;
  51. { timer t; t.set_print_mode(0); t.start_timer();
  52. r = Pi();
  53. t.stop_timer(); cerr << t << endl;
  54. }
  55. cout << r << endl << endl;
  56. }
  57. cerr << "eulerconst\n";
  58. { bigfloat r;
  59. { timer t; t.set_print_mode(0); t.start_timer();
  60. r = Euler();
  61. t.stop_timer(); cerr << t << endl;
  62. }
  63. cout << r << endl << endl;
  64. }
  65. cerr << "e\n";
  66. { bigfloat r;
  67. { timer t; t.set_print_mode(0); t.start_timer();
  68. r = E();
  69. t.stop_timer(); cerr << t << endl;
  70. }
  71. cout << r << endl << endl;
  72. }
  73. cerr << "exp\n";
  74. { bigfloat r = exp(-x1);
  75. { timer t; t.set_print_mode(0); t.start_timer();
  76. for (int rep = repetitions; rep > 0; rep--)
  77. { r = exp(-x1); }
  78. t.stop_timer(); cerr << t << endl;
  79. }
  80. cout << r << endl << endl;
  81. }
  82. cerr << "log\n";
  83. { bigfloat r = log(x2);
  84. { timer t; t.set_print_mode(0); t.start_timer();
  85. for (int rep = repetitions; rep > 0; rep--)
  86. { r = log(x2); }
  87. t.stop_timer(); cerr << t << endl;
  88. }
  89. cout << r << endl << endl;
  90. }
  91. cerr << "sin\n";
  92. { bigfloat r = sin(5*x1);
  93. { timer t; t.set_print_mode(0); t.start_timer();
  94. for (int rep = repetitions; rep > 0; rep--)
  95. { r = sin(5*x1); }
  96. t.stop_timer(); cerr << t << endl;
  97. }
  98. cout << r << endl << endl;
  99. }
  100. cerr << "cos\n";
  101. { bigfloat r = cos(5*x1);
  102. { timer t; t.set_print_mode(0); t.start_timer();
  103. for (int rep = repetitions; rep > 0; rep--)
  104. { r = cos(5*x1); }
  105. t.stop_timer(); cerr << t << endl;
  106. }
  107. cout << r << endl << endl;
  108. }
  109. cerr << "asin\n";
  110. { bigfloat r = asin(x3);
  111. { timer t; t.set_print_mode(0); t.start_timer();
  112. for (int rep = repetitions; rep > 0; rep--)
  113. { r = asin(x3); }
  114. t.stop_timer(); cerr << t << endl;
  115. }
  116. cout << r << endl << endl;
  117. }
  118. cerr << "acos\n";
  119. { bigfloat r = acos(x3);
  120. { timer t; t.set_print_mode(0); t.start_timer();
  121. for (int rep = repetitions; rep > 0; rep--)
  122. { r = acos(x3); }
  123. t.stop_timer(); cerr << t << endl;
  124. }
  125. cout << r << endl << endl;
  126. }
  127. cerr << "atan\n";
  128. { bigfloat r = atan(x3);
  129. { timer t; t.set_print_mode(0); t.start_timer();
  130. for (int rep = repetitions; rep > 0; rep--)
  131. { r = atan(x3); }
  132. t.stop_timer(); cerr << t << endl;
  133. }
  134. cout << r << endl << endl;
  135. }
  136. cerr << "sinh\n";
  137. { bigfloat r = sinh(x2);
  138. { timer t; t.set_print_mode(0); t.start_timer();
  139. for (int rep = repetitions; rep > 0; rep--)
  140. { r = sinh(x2); }
  141. t.stop_timer(); cerr << t << endl;
  142. }
  143. cout << r << endl << endl;
  144. }
  145. cerr << "cosh\n";
  146. { bigfloat r = cosh(x2);
  147. { timer t; t.set_print_mode(0); t.start_timer();
  148. for (int rep = repetitions; rep > 0; rep--)
  149. { r = cosh(x2); }
  150. t.stop_timer(); cerr << t << endl;
  151. }
  152. cout << r << endl << endl;
  153. }
  154. cerr << "asinh\n";
  155. { bigfloat r = asinh(x3);
  156. { timer t; t.set_print_mode(0); t.start_timer();
  157. for (int rep = repetitions; rep > 0; rep--)
  158. { r = asinh(x3); }
  159. t.stop_timer(); cerr << t << endl;
  160. }
  161. cout << r << endl << endl;
  162. }
  163. cerr << "acosh\n";
  164. { bigfloat r = acosh(1+x3);
  165. { timer t; t.set_print_mode(0); t.start_timer();
  166. for (int rep = repetitions; rep > 0; rep--)
  167. { r = acosh(1+x3); }
  168. t.stop_timer(); cerr << t << endl;
  169. }
  170. cout << r << endl << endl;
  171. }
  172. cerr << "atanh\n";
  173. { bigfloat r = atanh(x3);
  174. { timer t; t.set_print_mode(0); t.start_timer();
  175. for (int rep = repetitions; rep > 0; rep--)
  176. { r = atanh(x3); }
  177. t.stop_timer(); cerr << t << endl;
  178. }
  179. cout << r << endl << endl;
  180. }
  181. }