4 #include <UnitTest++.h>
23 TEST(TestLogFactorial)
37 complex<double> y =
cdgamma( complex<double>(1.,0.) );
39 y =
cdgamma( complex<double>(2.,0.) );
41 y =
cdgamma( complex<double>(11.,0.) );
43 y =
cdgamma( complex<double>(-0.5,0.) );
44 CHECK(
fp_equal( y.real(), -3.544907701811032054596334966682277e0, 10 ) &&
46 y =
cdgamma( complex<double>(0.,1.) );
47 CHECK(
fp_equal( y.real(), -1.549498283018106851249551304838863e-1, 10 ) &&
48 fp_equal( y.imag(), -4.980156681183560427136911174621973e-1, 10 ) );
49 y =
cdgamma( complex<double>(-1.,-2.) );
50 CHECK(
fp_equal( y.real(), -3.23612885501927256868232032760969e-2, 30 ) &&
51 fp_equal( y.imag(), -1.122942423463261735043406872030743e-2, 30 ) );
191 CHECK(
fp_equal( i0val, 1.02262687935159699112 ) );
192 CHECK(
fp_equal( i1val, 0.1516938400035927803287 ) );
194 CHECK(
fp_equal( i0val, 1.02262687935159699112*exp(-0.3) ) );
195 CHECK(
fp_equal( i1val, 0.1516938400035927803287*exp(-0.3) ) );
198 CHECK(
fp_equal( i0val, 1.02262687935159699112 ) );
199 CHECK(
fp_equal( i1val, -0.1516938400035927803287 ) );
201 CHECK(
fp_equal( i0val, 1.02262687935159699112*exp(-0.3) ) );
202 CHECK(
fp_equal( i1val, -0.1516938400035927803287*exp(-0.3) ) );
205 CHECK(
fp_equal( i0val, 306692993.6403647456135 ) );
206 CHECK(
fp_equal( i1val, 299639606.8773789797263 ) );
208 CHECK(
fp_equal( i0val, 306692993.6403647456135*exp(-22.) ) );
209 CHECK(
fp_equal( i1val, 299639606.8773789797263*exp(-22.) ) );
212 CHECK(
fp_equal( i0val, 306692993.6403647456135 ) );
213 CHECK(
fp_equal( i1val, -299639606.8773789797263 ) );
215 CHECK(
fp_equal( i0val, 306692993.6403647456135*exp(-22.) ) );
216 CHECK(
fp_equal( i1val, -299639606.8773789797263*exp(-22.) ) );
221 CHECK_THROW(
bessel_k0(0.), domain_error );
222 CHECK_THROW(
bessel_k0(-1.), domain_error );
236 CHECK_THROW(
bessel_k1(0.), domain_error );
237 CHECK_THROW(
bessel_k1(-1.), domain_error );
252 CHECK_THROW(
bessel_k0_k1(0., &k0val, &k1val), domain_error );
253 CHECK_THROW(
bessel_k0_k1(-1., &k0val, &k1val), domain_error );
255 CHECK(
fp_equal( k0val, 1.372460060544297376645 ) );
256 CHECK(
fp_equal( k1val, 3.055992033457324978851 ) );
258 CHECK(
fp_equal( k0val, 1.372460060544297376645*exp(0.3) ) );
259 CHECK(
fp_equal( k1val, 3.055992033457324978851*exp(0.3) ) );
262 CHECK(
fp_equal( k0val, 7.412351614084865368946e-11 ) );
263 CHECK(
fp_equal( k1val, 7.578981163485331089804e-11 ) );
265 CHECK(
fp_equal( k0val, 7.412351614084865368946e-11*exp(22.) ) );
266 CHECK(
fp_equal( k1val, 7.578981163485331089804e-11*exp(22.) ) );
303 TEST(TestIgamc_scaled)
317 CHECK(
fp_equal_tol(
expn(1,0.25), 0.25*0.9408157528 - log(0.25) - EULER, 1.e-10 ) );
343 CHECK(
fp_equal_tol(
e1(0.25), 0.25*0.9408157528 - log(0.25) - EULER, 2.e-7 ) );
354 CHECK(
fp_equal_tol(
e2(0.25), 0.8643037 + log(0.25)/4., 1.e-7 ) );
364 CHECK(
fp_equal_tol(
erf(1.e-10), 1.1283791671081724525e-10, 3.e-21 ) );
469 u.step(); u.step(); u.step();
478 long a=1,b=2,c=3,s=a+b+c;
479 double cc =
ipow(-1,s)/sqrt(
double((2*b+1)*(2*c+1)));
484 CHECK(
sjs( 0, 6, 2, 4, 2, 2 ) == 0. );
486 CHECK(
sjs( 2, 2, 0, 0, 4, 2 ) == 0. );
488 CHECK(
sjs( 2, 4, 6, 6, 2, 6 ) == 0. );
490 CHECK(
sjs( 2, 6, 4, 0, 4, 2 ) == 0. );
493 for(
int j1=0; j1 < 5; ++j1 )
494 for(
int j2=0; j2 < 5; ++j2 )
495 for(
int j3=0; j3 < 5; ++j3 )
496 for(
int j4=0; j4 < 5; ++j4 )
497 for(
int j5=0; j5 < 5; ++j5 )
498 for(
int j6=0; j6 < 5; ++j6 )
500 double s1 =
sjs( j1, j2, j3, j4, j5, j6 );
508 double s2 =
SixJFull( j1, j2, j3, j4, j5, j6 );
516 double s1 =
sjs( 42, 38, 34, 46, 36, 32 );
517 double s2 = -146218147./1778945129108.*sqrt(20735./57.);
519 s1 =
sjs( 46, 44, 42, 40, 38, 36 );
520 s2 = -16185716849919./4093621176253.*sqrt(201./135605470.);
522 s1 =
sjs( 43, 39, 40, 12, 48, 49 );
523 s2 = 1111./11600540.*sqrt(2982639./595.);
528 for(
int i=0; i < 1000; ++i )
530 int j1, j2, j3, j4, j5, j6;
531 const int JMAX = 110;
544 s1 =
sjs( j1, j2, j3, j4, j5, j6 );
545 s2 =
SixJFull( j1, j2, j3, j4, j5, j6 );
554 long a=1,b=2,c=3,s=a+b+c;
555 double cc = pow(-1,s)/sqrt((2*b+1)*(2*c+1));
558 double l1min, l1max, lmatch;
559 rec6j(sixcof, b, c, 0, c, b, &l1min, &l1max, &lmatch, NPT, &ier);
560 CHECK(
fp_equal_tol( sixcof[a-(
int)l1min], cc, 1.e-15 ) );
564 rec6j(sixcof, 3, 1, 2, 1, 1, &l1min, &l1max, &lmatch, NPT, &ier);
567 rec6j(sixcof, 1, 0, 0, 2, 1, &l1min, &l1max, &lmatch, NPT, &ier);
570 rec6j(sixcof, 1, 3, 3, 1, 3, &l1min, &l1max, &lmatch, NPT, &ier);
573 rec6j(sixcof, 3, 2, 0, 2, 1, &l1min, &l1max, &lmatch, NPT, &ier);
577 for(
int j2=0; j2 < 5; ++j2 )
578 for(
int j3=0; j3 < 5; ++j3 )
579 for(
int j4=0; j4 < 5; ++j4 )
580 for(
int j5=0; j5 < 5; ++j5 )
581 for(
int j6=0; j6 < 5; ++j6 )
583 rec6j(sixcof, 0.5*j2, 0.5*j3, 0.5*j4, 0.5*j5, 0.5*j6, &l1min, &l1max, &lmatch, NPT, &ier);
584 for(
int j1=0; j1 < 5; ++j1 )
586 double pos = (0.5*j1-l1min);
590 CHECK( ier == -1 || pos !=
int(pos) ||
591 0.5*j1 < l1min || 0.5*j1 > l1max );
596 double s1 = sixcof[int(pos)];
597 double s2 =
SixJFull( j1, j2, j3, j4, j5, j6 );
606 rec6j(sixcof, 19, 17, 23, 18, 16, &l1min, &l1max, &lmatch, NPT, &ier);
607 double s1 = sixcof[int(21-l1min)];
608 double s2 = -146218147./1778945129108.*sqrt(20735./57.);
610 rec6j(sixcof, 22, 21, 20, 19, 18, &l1min, &l1max, &lmatch, NPT, &ier);
611 s1 = sixcof[int(23-l1min)];
612 s2 = -16185716849919./4093621176253.*sqrt(201./135605470.);
614 rec6j(sixcof, 19.5, 20, 6, 24, 24.5, &l1min, &l1max, &lmatch, NPT, &ier);
615 s1 = sixcof[int(21.5-l1min)];
616 s2 = 1111./11600540.*sqrt(2982639./595.);
621 for(
int i=0; i < 1000; ++i )
623 int j1, j2, j3, j4, j5, j6;
624 const int JMAX = 110;
637 rec6j(sixcof, 0.5*j2, 0.5*j3, 0.5*j4, 0.5*j5, 0.5*j6,
638 &l1min, &l1max, &lmatch, NPT, &ier);
639 s1 = sixcof[int(0.5*j1-l1min)];
640 s2 =
SixJFull( j1, j2, j3, j4, j5, j6 );
648 rec6j(sixcof, 85., 84., 89.5, 89.5, 89.5, &l1min, &l1max, &lmatch, NPT, &ier);
649 s1 = sixcof[int(86.-l1min)];
650 CHECK(
fp_equal_tol( s1, 3.3988213869175631e-08, 4.e-18 ) );
654 s1 = sixcof[int(1.-l1min)];
655 CHECK(
fp_equal_tol( s1, 0.0035632864755963242, 4.e-18 ) );
656 s1 = sixcof[int(169.-l1min)];
657 CHECK(
fp_equal_tol( s1, 1.785014472974611e-17, 2.e-31 ) );
674 for(
int i=0; i < 9; ++i )
677 for(
int i=0; i < NP; ++i )
684 for(
int i=1; i < NP; ++i )
685 integral += (y[i]+y[i-1])*(v[i]-v[i-1]);
687 integral +=
realnum(2.)*v[NP-1]*y[NP-1];
779 for(
int i=0; i < 9; ++i )
782 for(
int i=0; i < NP; ++i )
789 for(
int i=1; i < NP; ++i )
790 integral += (y[i]+y[i-1])*(v[i]-v[i-1]);
792 integral +=
realnum(2.)*v[NP-1]*y[NP-1];
805 CHECK(
MD5string( test ) ==
"d41d8cd98f00b204e9800998ecf8427e" );
809 test =
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
810 CHECK( test.length() == 55 );
811 CHECK(
MD5string( test ) ==
"426ec4ac35ad38d125f6efb39da03098" );
812 test =
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
813 CHECK( test.length() == 56 );
814 CHECK(
MD5string( test ) ==
"d03607b2c89adc0c4abf5a0f1d9e40c9" );
815 test =
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
816 CHECK( test.length() == 57 );
817 CHECK(
MD5string( test ) ==
"bac1b47748411cb6eee0cae3befb8377" );
818 string test64 =
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
819 test = test64 +
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
820 CHECK( test.length() == 64+55 );
821 CHECK(
MD5string( test ) ==
"10d49aad1fc69976376fbe7c8c5ed118" );
822 test = test64 +
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
823 CHECK( test.length() == 64+56 );
824 CHECK(
MD5string( test ) ==
"61ec7da14576f3b585038c6d72cd5bd5" );
825 test = test64 +
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
826 CHECK( test.length() == 64+57 );
827 CHECK(
MD5string( test ) ==
"f17a0475a26d0930e2a35bb320c10e0d" );
830 CHECK(
MD5string( test ) ==
"0256b9cea63bc1f97b8c5aea92c24a98" );
void bessel_i0_i1(double x, double *i0val, double *i1val)
double bessel_k0_scaled(double x)
double bessel_i1_scaled(double x)
double lfactorial(long n)
double bessel_i1(double x)
double SixJFull(long j1, long j2, long j3, long j4, long j5, long j6)
bool Triangle2(long J1, long J2, long J3)
bool fp_equal_tol(sys_float x, sys_float y, sys_float tol)
double sjs(long j1, long j2, long j3, long l1, long l2, long l3)
void bessel_i0_i1_scaled(double x, double *i0val, double *i1val)
double expn(int n, double x)
complex< double > cdgamma(complex< double > x)
void bessel_k0_k1(double x, double *k0val, double *k1val)
bool fp_equal(sys_float x, sys_float y, int n=3)
double bessel_k1(double x)
double bessel_i0_scaled(double x)
double bessel_i0(double x)
double bessel_jn(int n, double x)
void bessel_k0_k1_scaled(double x, double *k0val, double *k1val)
double bessel_y0(double x)
double bessel_j0(double x)
double bessel_j1(double x)
double igamc(double a, double x)
double igam(double a, double x)
long int ipow(long, long)
double bessel_yn(int n, double x)
double bessel_k1_scaled(double x)
void VoigtU(realnum a, const realnum v[], realnum y[], int n)
double bessel_y1(double x)
static const unsigned int NMD5
double e1_scaled(double x)
void rec6j(double *sixcof, double l2, double l3, double l4, double l5, double l6, double *l1min, double *l1max, double *lmatch, long ndim, long *ier)
double igamc_scaled(double a, double x)
double gegenbauer(long n, double al, double x)
double bessel_k0(double x)
string MD5string(const string &str)
void VoigtH(realnum a, const realnum v[], realnum y[], int n)