1. /* SMPBERN.CPP by K.Tsuru */
  2. const char* title = "<<< A sample program for tangent coefficient, Bernouilli and Euler numbers >>>\n";
  3. #include "sn.h"
  4. #include "getnum.h"
  5. #include "wait.h"
  6. #include "timer.h"
  7. void TnTableTest(uint N){
  8. SNBlock <SLong> T(N+1);
  9. Timer timer;
  10. double cpu_time;
  11. puts("Calculating tangent coefficients by TanCoeffTable() function.");
  12. timer.Start();
  13. TanCoeffTable(T, N);
  14. cpu_time = timer.Stop();
  15. for(uint n = 1; n<= N; n++){
  16. printf("T[%u]= ", n);
  17. T(n).Puts();
  18. }
  19. printf("CPU time = %.3f sec.\n", cpu_time);
  20. Wait();
  21. }
  22. void TanCoeffTest(uint N){
  23. SNBlock <SLong> T(N+1);
  24. Timer timer;
  25. double cpu_time;
  26. uint n;
  27. puts("Calcuating tangent coefficients by TanCoeff() function.");
  28. timer.Start();
  29. for(n = 1; n <= N; n++) T[n-1] = TanCoeff(n);
  30. cpu_time = timer.Stop();
  31. for(n = 1; n <= N; n++){
  32. printf("T[%u]=", n);
  33. T(n-1).Puts();
  34. }
  35. printf("CPU time = %.3f sec.\n", cpu_time);
  36. Wait();
  37. }
  38. void BnTableTest(uint N){
  39. SNBlock <SFraction> B(N+1);
  40. Timer timer;
  41. double cpu_time;
  42. puts("Calculating Bernouilli numbers by BernNumTable() function.");
  43. timer.Start();
  44. BernNumTable(B, N);
  45. cpu_time = timer.Stop();
  46. for(uint n = 1; n<= N; n++){
  47. printf("B[%u]= ", n);
  48. B(n).Puts();
  49. }
  50. printf("CPU time = %.3f sec.\n", cpu_time);
  51. Wait();
  52. }
  53. void BernNumTest(uint N){
  54. SNBlock <SFraction> B(N+1);
  55. Timer timer;
  56. double cpu_time;
  57. uint n;
  58. puts("Calculating Bernouilli numbers by BernNum() function with combL().");
  59. timer.Start();
  60. for(n = 1; n <= N; n++) B[n] = BernNum(n);
  61. cpu_time = timer.Stop();
  62. for(n = 1; n <= N; n++){
  63. printf("B[%u]= ", n);
  64. B(n).Puts();
  65. }
  66. printf("CPU time = %.3f sec.\n", cpu_time);
  67. Wait();
  68. }
  69. void EulerNumTest(uint N){
  70. SNBlock <SLong> E(N+1);
  71. Timer timer;
  72. double cpu_time;
  73. uint n;
  74. puts("Calculating Euler numbers by EulerNum() function.");
  75. timer.Start();
  76. for(n=0; n<= N; n++) E[n] = EulerNum(n);
  77. cpu_time = timer.Stop();
  78. for(n = 0; n<= N; n++){
  79. printf("E[%u]=", n);
  80. E(n).Puts();
  81. }
  82. printf("CPU time = %.3f sec.\n", cpu_time);
  83. Wait();
  84. }
  85. int main(){
  86. uint N;
  87. ErrorPuts(title);
  88. fprintf(stderr,"How many terms do you want? ");
  89. N = GetInt();
  90. TnTableTest(N);
  91. TanCoeffTest(N);
  92. BnTableTest(N);
  93. BernNumTest(N);
  94. EulerNumTest(N);
  95. Ending();
  96. return EXIT_SUCCESS;
  97. }

smpbern.cpp : last modifiled at 2007/04/18 14:09:40(2,375 bytes)
created at 2010/01/13 16:21:47
The creation time of this html file is 2010/01/21 10:02:02 (Thu Jan 21 10:02:02 2010).