7 |
|
|
8 |
|
double SHFunc::getValueAt(double costheta, double phi) { |
9 |
|
|
10 |
< |
double f, p, phase; |
10 |
> |
double p, phase; |
11 |
|
|
12 |
– |
// incredibly inefficient way to get the normalization, but |
13 |
– |
// we use a lookup table in the factorial code: |
14 |
– |
|
15 |
– |
// normalization factor: |
16 |
– |
f = sqrt( (2*L+1)/(4.0*M_PI) * Fac(L-M) / Fac(L+M) ); |
12 |
|
// associated Legendre polynomial |
13 |
|
p = LegendreP(L,M,costheta); |
14 |
|
|
17 |
|
} else { |
18 |
|
phase = cos((double)M * phi); |
19 |
|
} |
25 |
– |
|
20 |
|
|
21 |
< |
return coefficient*f*p*phase; |
21 |
> |
return coefficient*p*phase; |
22 |
|
|
23 |
|
} |
24 |
|
//-----------------------------------------------------------------------------// |
40 |
|
double SHFunc::LegendreP (int l, int m, double x) { |
41 |
|
// check parameters |
42 |
|
if (m < 0 || m > l || fabs(x) > 1.0) { |
43 |
< |
printf("LegendreP got a bad argument\n"); |
43 |
> |
printf("LegendreP got a bad argument: l = %d\tm = %d\tx = %lf\n", l, m, x); |
44 |
|
return NAN; |
45 |
|
} |
46 |
|
|
71 |
|
} |
72 |
|
} |
73 |
|
|
80 |
– |
double SHFunc::Fac (int n) { |
81 |
– |
|
82 |
– |
static double facn[31] = { |
83 |
– |
1.0, |
84 |
– |
1.0, |
85 |
– |
2.0, |
86 |
– |
6.0, |
87 |
– |
24.0, |
88 |
– |
120.0, |
89 |
– |
720.0, |
90 |
– |
5040.0, |
91 |
– |
40320.0, |
92 |
– |
362880.0, |
93 |
– |
3628800.0, |
94 |
– |
39916800.0, |
95 |
– |
479001600.0, |
96 |
– |
6227020800.0, |
97 |
– |
87178291200.0, |
98 |
– |
1.307674368e12, |
99 |
– |
2.0922789888e13, |
100 |
– |
3.55687428096e14, |
101 |
– |
6.402373705728e15, |
102 |
– |
1.21645100408832e17, |
103 |
– |
2.43290200817664e18, |
104 |
– |
5.109094217170944e19, |
105 |
– |
1.12400072777760768e21, |
106 |
– |
2.585201673888497664e22, |
107 |
– |
6.2044840173323943936e23, |
108 |
– |
1.5511210043330985984e25, |
109 |
– |
4.03291461126605635584e26, |
110 |
– |
1.0888869450418352160768e28, |
111 |
– |
3.04888344611713860501504e29, |
112 |
– |
8.841761993739701954543616e30, |
113 |
– |
2.6525285981219105863630848e32 |
114 |
– |
}; |
115 |
– |
|
116 |
– |
|
117 |
– |
static int nmax = 0; |
118 |
– |
static double xmin, xmax; |
119 |
– |
|
120 |
– |
if (n < 0) { |
121 |
– |
printf("factorial of negative integer undefined\n"); |
122 |
– |
return NAN; |
123 |
– |
} |
124 |
– |
|
125 |
– |
if (n <= 30) return facn[n]; |
126 |
– |
else { |
127 |
– |
printf("n is so large that Fac(n) will overflow\n"); |
128 |
– |
return NAN; |
129 |
– |
} |
130 |
– |
} |