--- trunk/SHAPES/SHFunc.cpp 2004/06/23 22:43:54 1291 +++ trunk/SHAPES/SHFunc.cpp 2004/06/24 15:31:52 1295 @@ -9,11 +9,10 @@ double SHFunc::getValueAt(double costheta, double phi) double f, p, phase; - // incredibly inefficient way to get the normalization, but - // we use a lookup table in the factorial code: + // incredibly inefficient way to get the normalization // normalization factor: - f = sqrt( (2*L+1)/(4.0*M_PI) * Fac(L-M) / Fac(L+M) ); + f = sqrt( (2*L+1)/(4.0*M_PI) * Fact(L-M) / Fact(L+M) ); // associated Legendre polynomial p = LegendreP(L,M,costheta); @@ -22,7 +21,6 @@ double SHFunc::getValueAt(double costheta, double phi) } else { phase = cos((double)M * phi); } - return coefficient*f*p*phase; @@ -77,54 +75,13 @@ double SHFunc::Fac (int n) { } } -double SHFunc::Fac (int n) { +double SHFunc::Fact(double n) { - static double facn[31] = { - 1.0, - 1.0, - 2.0, - 6.0, - 24.0, - 120.0, - 720.0, - 5040.0, - 40320.0, - 362880.0, - 3628800.0, - 39916800.0, - 479001600.0, - 6227020800.0, - 87178291200.0, - 1.307674368e12, - 2.0922789888e13, - 3.55687428096e14, - 6.402373705728e15, - 1.21645100408832e17, - 2.43290200817664e18, - 5.109094217170944e19, - 1.12400072777760768e21, - 2.585201673888497664e22, - 6.2044840173323943936e23, - 1.5511210043330985984e25, - 4.03291461126605635584e26, - 1.0888869450418352160768e28, - 3.04888344611713860501504e29, - 8.841761993739701954543616e30, - 2.6525285981219105863630848e32 - }; - - - static int nmax = 0; - static double xmin, xmax; - - if (n < 0) { - printf("factorial of negative integer undefined\n"); - return NAN; + if (n < 0.0) return NAN; + else { + if (n < 2.0) return 1.0; + else + return n*Fact(n-1.0); } - if (n <= 30) return facn[n]; - else { - printf("n is so large that Fac(n) will overflow\n"); - return NAN; - } }