50{
51 G4double t = 0.0, aa = 0.0, bb = 0.0, cc = 0.0, factor = 1.0;
52 G4double max = 0.0,
min = infin, xxx = 0.0, x = 0.0, sc = 0.0, bnd = 0.0;
53 G4double xm = 0.0, ff = 0.0, df = 0.0, dx = 0.0;
54 G4int cnt = 0, nz = 0, i = 0, j = 0, jj = 0, l = 0, nm1 = 0, zerok = 0;
56
57
58
59 static const G4double xx = std::sqrt(0.5);
60 static const G4double rot = 94.0 * deg;
61 static const G4double cosr = std::cos(rot), sinr = std::sin(rot);
63 n = degr;
64
65
66
67 if(!(op[0] != 0.0))
68 {
69 return -1;
70 }
71
72
73
74 while(!(op[n] != 0.0))
75 {
76 j = degr - n;
77 zeror[j] = 0.0;
78 zeroi[j] = 0.0;
80 }
81 if(n < 1)
82 {
83 return -1;
84 }
85
86
87
88 std::vector<G4double> temp(degr + 1);
89 std::vector<G4double> pt(degr + 1);
90
91 p.assign(degr + 1, 0);
92 qp.assign(degr + 1, 0);
93 k.assign(degr + 1, 0);
94 qk.assign(degr + 1, 0);
95 svk.assign(degr + 1, 0);
96
97
98
99 for(i = 0; i <= n; ++i)
100 {
101 p[i] = op[i];
102 }
103
104 do
105 {
106 if(n == 1)
107 {
108 zeror[degr - 1] = -p[1] / p[0];
109 zeroi[degr - 1] = 0.0;
110 n -= 1;
111 return degr - n;
112 }
113 if(n == 2)
114 {
115 Quadratic(p[0], p[1], p[2], &zeror[degr - 2], &zeroi[degr - 2],
116 &zeror[degr - 1], &zeroi[degr - 1]);
117 n -= 2;
118 return degr - n;
119 }
120
121
122
125 for(i = 0; i <= n; ++i)
126 {
127 x = std::fabs(p[i]);
128 if(x > max)
129 {
131 }
132 if(x != 0.0 && x < min)
133 {
135 }
136 }
137
138
139
140
141
142
143
145
146 if(((sc <= 1.0) && (max >= 10.0)) || ((sc > 1.0) && (infin / sc >= max)) ||
147 ((infin / sc >= max) && (max >= 10)))
148 {
149 if(!(sc != 0.0))
150 {
151 sc = smalno;
152 }
154 factor = power->
powN(base, l);
155 if(factor != 1.0)
156 {
157 for(i = 0; i <= n; ++i)
158 {
159 p[i] = factor * p[i];
160 }
161 }
162 }
163
164
165
166 for(i = 0; i <= n; ++i)
167 {
168 pt[i] = (std::fabs(p[i]));
169 }
170 pt[n] = -pt[n];
171
172
173
175
176
177
178 if(pt[n - 1] != 0.0)
179 {
180 xm = -pt[
n] / pt[
n - 1];
181 if(xm < x)
182 {
183 x = xm;
184 }
185 }
186
187
188
189 while(1)
190 {
191 xm = x * 0.1;
192 ff = pt[0];
193 for(i = 1; i <=
n; ++i)
194 {
195 ff = ff * xm + pt[i];
196 }
197 if(ff <= 0.0)
198 {
199 break;
200 }
201 x = xm;
202 }
203 dx = x;
204
205
206
207 while(std::fabs(dx / x) > 0.005)
208 {
209 ff = pt[0];
210 df = ff;
211 for(i = 1; i <
n; ++i)
212 {
213 ff = ff * x + pt[i];
214 df = df * x + ff;
215 }
217 dx = ff / df;
218 x -= dx;
219 }
220 bnd = x;
221
222
223
224
226 for(i = 1; i <
n; ++i)
227 {
229 }
230 k[0] = p[0];
233 zerok = (k[
n - 1] == 0);
234 for(jj = 0; jj < 5; ++jj)
235 {
237 if(!zerok)
238 {
239
240
241 t = -aa / cc;
242 for(i = 0; i < nm1; ++i)
243 {
245 k[j] = t * k[j - 1] + p[j];
246 }
247 k[0] = p[0];
248 zerok = (std::fabs(k[n - 1]) <= std::fabs(bb) * eta * 10.0);
249 }
250 else
251 {
252 for(i = 0; i < nm1; ++i)
253 {
255 k[j] = k[j - 1];
256 }
257 k[0] = 0.0;
258 zerok = (!(k[
n - 1] != 0.0));
259 }
260 }
261
262
263
264 for(i = 0; i <
n; ++i)
265 {
266 temp[i] = k[i];
267 }
268
269
270
271 for(cnt = 0; cnt < 20; ++cnt)
272 {
273
274
275
276
277
278 xxx = cosr * xo - sinr * yo;
279 yo = sinr * xo + cosr * yo;
280 xo = xxx;
281 sr = bnd * xo;
282 si = bnd * yo;
283 u = -2.0 * sr;
284 v = bnd;
285 ComputeFixedShiftPolynomial(20 * (cnt + 1), &nz);
286 if(nz != 0)
287 {
288
289
290
291
292
294 zeror[j] = szr;
295 zeroi[j] = szi;
297 for(i = 0; i <=
n; ++i)
298 {
299 p[i] = qp[i];
300 }
301 if(nz != 1)
302 {
303 zeror[j + 1] = lzr;
304 zeroi[j + 1] = lzi;
305 }
306 break;
307 }
308 else
309 {
310
311
312
313 for(i = 0; i <
n; ++i)
314 {
315 k[i] = temp[i];
316 }
317 }
318 }
319 } while(nz != 0);
320
321
322
324}
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
G4double G4Log(G4double x)
static G4Pow * GetInstance()
G4double powN(G4double x, G4int n) const
T max(const T t1, const T t2)
brief Return the largest of the two arguments
T min(const T t1, const T t2)
brief Return the smallest of the two arguments