189 lines
3.7 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
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/float.h>
  5. #include <cln/float_io.h>
  6. #include <cln/real.h>
  7. #include <cln/real_io.h>
  8. #include <cln/complex.h>
  9. #include <cln/complex_io.h>
  10. #include <cstdlib>
  11. #include <cstring>
  12. #include <cln/timing.h>
  13. using namespace std;
  14. using namespace cln;
  15. int main (int argc, char * argv[])
  16. {
  17. int digits = 100;
  18. int repetitions = 1;
  19. while (argc >= 3) {
  20. if (!strcmp(argv[1],"-r")) {
  21. repetitions = atoi(argv[2]);
  22. argc -= 2; argv += 2;
  23. continue;
  24. }
  25. if (!strcmp(argv[1],"-n")) {
  26. digits = atoi(argv[2]);
  27. argc -= 2; argv += 2;
  28. continue;
  29. }
  30. break;
  31. }
  32. if (argc < 1)
  33. exit(1);
  34. cerr << "Number of digits: " << digits << endl;
  35. cerr << "Number of repetitions (except for pi,euler,e): " << repetitions << endl;
  36. float_format_t prec = float_format(digits);
  37. cl_F x1 = sqrt(cl_float(2,prec));
  38. cl_F x2 = sqrt(cl_float(3,prec));
  39. cl_F x3 = The(cl_F)(log(cl_float(2,prec)));
  40. cerr << "multiplication" << endl;
  41. { cl_F r = x1*x2;
  42. { CL_TIMING;
  43. for (int rep = repetitions; rep > 0; rep--)
  44. { r = x1*x2; }
  45. }
  46. cout << r << endl << endl;
  47. }
  48. cerr << "sqrt" << endl;
  49. { cl_F r = sqrt(x3);
  50. { CL_TIMING;
  51. for (int rep = repetitions; rep > 0; rep--)
  52. { r = sqrt(x3); }
  53. }
  54. cout << r << endl << endl;
  55. }
  56. cerr << "pi" << endl;
  57. { cl_F r;
  58. { CL_TIMING; r = pi(prec); }
  59. cout << r << endl << endl;
  60. }
  61. cerr << "eulerconst" << endl;
  62. { cl_F r;
  63. { CL_TIMING; r = eulerconst(prec); }
  64. cout << r << endl << endl;
  65. }
  66. cerr << "e" << endl;
  67. { cl_F r;
  68. { CL_TIMING; r = exp1(prec); }
  69. cout << r << endl << endl;
  70. }
  71. cerr << "exp" << endl;
  72. { cl_F r = exp(-x1);
  73. { CL_TIMING;
  74. for (int rep = repetitions; rep > 0; rep--)
  75. { r = exp(-x1); }
  76. }
  77. cout << r << endl << endl;
  78. }
  79. cerr << "log" << endl;
  80. { cl_N r = log(x2);
  81. { CL_TIMING;
  82. for (int rep = repetitions; rep > 0; rep--)
  83. { r = log(x2); }
  84. }
  85. cout << r << endl << endl;
  86. }
  87. cerr << "sin" << endl;
  88. { cl_R r = sin(5*x1);
  89. { CL_TIMING;
  90. for (int rep = repetitions; rep > 0; rep--)
  91. { r = sin(5*x1); }
  92. }
  93. cout << r << endl << endl;
  94. }
  95. cerr << "cos" << endl;
  96. { cl_R r = cos(5*x1);
  97. { CL_TIMING;
  98. for (int rep = repetitions; rep > 0; rep--)
  99. { r = cos(5*x1); }
  100. }
  101. cout << r << endl << endl;
  102. }
  103. cerr << "asin" << endl;
  104. { cl_N r = asin(x3);
  105. { CL_TIMING;
  106. for (int rep = repetitions; rep > 0; rep--)
  107. { r = asin(x3); }
  108. }
  109. cout << r << endl << endl;
  110. }
  111. cerr << "acos" << endl;
  112. { cl_N r = acos(x3);
  113. { CL_TIMING;
  114. for (int rep = repetitions; rep > 0; rep--)
  115. { r = acos(x3); }
  116. }
  117. cout << r << endl << endl;
  118. }
  119. cerr << "atan" << endl;
  120. { cl_F r = atan(x3);
  121. { CL_TIMING;
  122. for (int rep = repetitions; rep > 0; rep--)
  123. { r = atan(x3); }
  124. }
  125. cout << r << endl << endl;
  126. }
  127. cerr << "sinh" << endl;
  128. { cl_F r = sinh(x2);
  129. { CL_TIMING;
  130. for (int rep = repetitions; rep > 0; rep--)
  131. { r = sinh(x2); }
  132. }
  133. cout << r << endl << endl;
  134. }
  135. cerr << "cosh" << endl;
  136. { cl_F r = cosh(x2);
  137. { CL_TIMING;
  138. for (int rep = repetitions; rep > 0; rep--)
  139. { r = cosh(x2); }
  140. }
  141. cout << r << endl << endl;
  142. }
  143. cerr << "asinh" << endl;
  144. { cl_N r = asinh(x3);
  145. { CL_TIMING;
  146. for (int rep = repetitions; rep > 0; rep--)
  147. { r = asinh(x3); }
  148. }
  149. cout << r << endl << endl;
  150. }
  151. cerr << "acosh" << endl;
  152. { cl_N r = acosh(1+x3);
  153. { CL_TIMING;
  154. for (int rep = repetitions; rep > 0; rep--)
  155. { r = acosh(1+x3); }
  156. }
  157. cout << r << endl << endl;
  158. }
  159. cerr << "atanh" << endl;
  160. { cl_N r = atanh(x3);
  161. { CL_TIMING;
  162. for (int rep = repetitions; rep > 0; rep--)
  163. { r = atanh(x3); }
  164. }
  165. cout << r << endl << endl;
  166. }
  167. }