ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/SHAPES/SHFunc.cpp
(Generate patch)

Comparing trunk/SHAPES/SHFunc.cpp (file contents):
Revision 1291 by gezelter, Wed Jun 23 22:43:54 2004 UTC vs.
Revision 1295 by gezelter, Thu Jun 24 15:31:52 2004 UTC

# Line 9 | Line 9 | double SHFunc::getValueAt(double costheta, double phi)
9  
10    double f, p, phase;
11  
12 <  // incredibly inefficient way to get the normalization, but
13 <  // we use a lookup table in the factorial code:
12 >  // incredibly inefficient way to get the normalization
13  
14    // normalization factor:
15 <  f = sqrt( (2*L+1)/(4.0*M_PI) * Fac(L-M) / Fac(L+M) );
15 >  f = sqrt( (2*L+1)/(4.0*M_PI) * Fact(L-M) / Fact(L+M) );
16    // associated Legendre polynomial
17    p = LegendreP(L,M,costheta);
18    
# Line 22 | Line 21 | double SHFunc::getValueAt(double costheta, double phi)
21    } else {
22      phase = cos((double)M * phi);
23    }
25
24    
25    return coefficient*f*p*phase;
26  
# Line 77 | Line 75 | double SHFunc::Fac (int n) {
75    }
76   }
77  
78 < double SHFunc::Fac (int n) {
78 > double SHFunc::Fact(double n) {
79  
80 <  static double facn[31] = {
81 <    1.0,
82 <    1.0,
83 <    2.0,
84 <    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;
80 >  if (n < 0.0) return NAN;
81 >  else {
82 >    if (n < 2.0) return 1.0;
83 >    else
84 >      return n*Fact(n-1.0);
85    }
86    
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  }  
87   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines