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