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.

167 lines
4.3 KiB

25 years ago
  1. #include <LiDIA/bigfloat.h>
  2. #include <LiDIA/timer.h>
  3. int main (int argc, char * argv[])
  4. {
  5. int repetitions = 1;
  6. if ((argc >= 3) && !strcmp(argv[1],"-r")) {
  7. repetitions = atoi(argv[2]);
  8. argc -= 2; argv += 2;
  9. }
  10. if (argc < 1)
  11. exit(1);
  12. bigfloat::precision(1000);
  13. cerr << "pi\n";
  14. { bigfloat p;
  15. { timer t; t.set_print_mode(0); t.start_timer();
  16. p = Pi();
  17. t.stop_timer(); cerr << t << endl;
  18. }
  19. { timer t; t.set_print_mode(0); t.start_timer();
  20. for (int rep = repetitions; rep > 0; rep--)
  21. { bigfloat p = Pi(); }
  22. t.stop_timer(); cerr << t << endl;
  23. }
  24. cout << p << endl << endl;
  25. }
  26. cerr << "gamma\n";
  27. { bigfloat p;
  28. { timer t; t.set_print_mode(0); t.start_timer();
  29. p = Euler();
  30. t.stop_timer(); cerr << t << endl;
  31. }
  32. { timer t; t.set_print_mode(0); t.start_timer();
  33. for (int rep = repetitions; rep > 0; rep--)
  34. { bigfloat p = Euler(); }
  35. t.stop_timer(); cerr << t << endl;
  36. }
  37. cout << p << endl << endl;
  38. }
  39. cerr << "e\n";
  40. { bigfloat p = E();
  41. { timer t; t.set_print_mode(0); t.start_timer();
  42. for (int rep = repetitions; rep > 0; rep--)
  43. { bigfloat p = E(); }
  44. t.stop_timer(); cerr << t << endl;
  45. }
  46. cout << p << endl << endl;
  47. }
  48. cerr << "sqrt(3)\n";
  49. { bigfloat p = sqrt((bigfloat)3);
  50. { timer t; t.set_print_mode(0); t.start_timer();
  51. for (int rep = repetitions; rep > 0; rep--)
  52. { bigfloat p = sqrt((bigfloat)3); }
  53. t.stop_timer(); cerr << t << endl;
  54. }
  55. cout << p << endl << endl;
  56. }
  57. cerr << "exp(log(2))\n";
  58. { bigfloat p = exp(log((bigfloat)2));
  59. { timer t; t.set_print_mode(0); t.start_timer();
  60. for (int rep = repetitions; rep > 0; rep--)
  61. { bigfloat p = exp(log((bigfloat)2)); }
  62. t.stop_timer(); cerr << t << endl;
  63. }
  64. cout << p << endl << endl;
  65. }
  66. cerr << "log(exp(2))\n";
  67. { bigfloat p = log(exp((bigfloat)2));
  68. { timer t; t.set_print_mode(0); t.start_timer();
  69. for (int rep = repetitions; rep > 0; rep--)
  70. { bigfloat p = log(exp((bigfloat)2)); }
  71. t.stop_timer(); cerr << t << endl;
  72. }
  73. cout << p << endl << endl;
  74. }
  75. cerr << "sin(pi/3)\n";
  76. { bigfloat p = sin(Pi()/3);
  77. { timer t; t.set_print_mode(0); t.start_timer();
  78. for (int rep = repetitions; rep > 0; rep--)
  79. { bigfloat p = sin(Pi()/3); }
  80. t.stop_timer(); cerr << t << endl;
  81. }
  82. cout << p << endl << endl;
  83. }
  84. cerr << "cos(pi/3)\n";
  85. { bigfloat p = cos(Pi()/3);
  86. { timer t; t.set_print_mode(0); t.start_timer();
  87. for (int rep = repetitions; rep > 0; rep--)
  88. { bigfloat p = cos(Pi()/3); }
  89. t.stop_timer(); cerr << t << endl;
  90. }
  91. cout << p << endl << endl;
  92. }
  93. cerr << "arcsin(sqrt(3)/2)\n";
  94. { bigfloat p = asin(sqrt((bigfloat)3)/2);
  95. { timer t; t.set_print_mode(0); t.start_timer();
  96. for (int rep = repetitions; rep > 0; rep--)
  97. { bigfloat p = asin(sqrt((bigfloat)3)/2); }
  98. t.stop_timer(); cerr << t << endl;
  99. }
  100. cout << p << endl << endl;
  101. }
  102. cerr << "arccos(sqrt(3)/2)\n";
  103. { bigfloat p = acos(sqrt((bigfloat)3)/2);
  104. { timer t; t.set_print_mode(0); t.start_timer();
  105. for (int rep = repetitions; rep > 0; rep--)
  106. { bigfloat p = acos(sqrt((bigfloat)3)/2); }
  107. t.stop_timer(); cerr << t << endl;
  108. }
  109. cout << p << endl << endl;
  110. }
  111. cerr << "sinh(log(2))\n";
  112. { bigfloat p = sinh(log((bigfloat)2));
  113. { timer t; t.set_print_mode(0); t.start_timer();
  114. for (int rep = repetitions; rep > 0; rep--)
  115. { bigfloat p = sinh(log((bigfloat)2)); }
  116. t.stop_timer(); cerr << t << endl;
  117. }
  118. cout << p << endl << endl;
  119. }
  120. cerr << "cosh(log(2))\n";
  121. { bigfloat p = cosh(log((bigfloat)2));
  122. { timer t; t.set_print_mode(0); t.start_timer();
  123. for (int rep = repetitions; rep > 0; rep--)
  124. { bigfloat p = cosh(log((bigfloat)2)); }
  125. t.stop_timer(); cerr << t << endl;
  126. }
  127. cout << p << endl << endl;
  128. }
  129. cerr << "arsinh(pi)\n";
  130. { bigfloat p = asinh(Pi());
  131. { timer t; t.set_print_mode(0); t.start_timer();
  132. for (int rep = repetitions; rep > 0; rep--)
  133. { bigfloat p = asinh(Pi()); }
  134. t.stop_timer(); cerr << t << endl;
  135. }
  136. cout << p << endl << endl;
  137. }
  138. cerr << "arcosh(pi)\n";
  139. { bigfloat p = acosh(Pi());
  140. { timer t; t.set_print_mode(0); t.start_timer();
  141. for (int rep = repetitions; rep > 0; rep--)
  142. { bigfloat p = acosh(Pi()); }
  143. t.stop_timer(); cerr << t << endl;
  144. }
  145. cout << p << endl << endl;
  146. }
  147. }