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


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/13 16:22:34 (Wed Jan 13 16:22:34 2010).