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.

190 lines
3.8 KiB

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