68 |
|
// |
69 |
|
RealType SphericalHarmonic::LegendreP(int l,int m, RealType x) { |
70 |
|
|
71 |
< |
RealType temp1, temp2, temp3, temp4, result; |
72 |
< |
RealType temp5; |
73 |
< |
int i, ll; |
71 |
> |
RealType result; |
72 |
|
|
73 |
|
if (fabs(x) > 1.0) { |
74 |
|
printf("LegendreP: x out of range: l = %d\tm = %d\tx = %lf\n", l, m, x); |
84 |
|
printf("LegendreP: m < 0: l = %d\tm = %d\tx = %lf\n", l, m, x); |
85 |
|
return std::numeric_limits <RealType>:: quiet_NaN(); |
86 |
|
} else { |
87 |
+ |
RealType temp1, temp2, temp3, temp4, temp5; |
88 |
|
temp3=1.0; |
89 |
|
|
90 |
|
if (m>0) { |
91 |
|
temp1=sqrt(1.0-pow(x,2)); |
92 |
|
temp5 = 1.0; |
93 |
< |
for (i=1;i<=m;++i) { |
93 |
> |
for (int i=1;i<=m;++i) { |
94 |
|
temp3 *= -temp5*temp1; |
95 |
|
temp5 += 2.0; |
96 |
|
} |
102 |
|
if (l==(m+1)) { |
103 |
|
result = temp4; |
104 |
|
} else { |
105 |
< |
for (ll=(m+2);ll<=l;++ll) { |
105 |
> |
for (int ll=(m+2);ll<=l;++ll) { |
106 |
|
temp2 = (x*(2.*ll-1.)*temp4-(ll+m-1.)*temp3)/(RealType)(ll-m); |
107 |
|
temp3=temp4; |
108 |
|
temp4=temp2; |