63{
64 G4double t=0.0, aa=0.0, bb=0.0, cc=0.0, factor=1.0;
65 G4double max=0.0, min=infin, xxx=0.0, x=0.0, sc=0.0, bnd=0.0;
66 G4double xm=0.0, ff=0.0, df=0.0, dx=0.0;
67 G4int cnt=0, nz=0, i=0, j=0, jj=0, l=0, nm1=0, zerok=0;
68
69
70
73 rot = 94.0*deg;
75 sinr = std::sin(rot);
76 n = degr;
77
78
79
80 if (!(op[0] != 0.0)) { return -1; }
81
82
83
84 while (!(op[n] != 0.0))
85 {
86 j = degr - n;
87 zeror[j] = 0.0;
88 zeroi[j] = 0.0;
90 }
91 if (n < 1) { return -1; }
92
93
94
95 std::vector<G4double> temp(degr+1) ;
96 std::vector<G4double> pt(degr+1) ;
97
98 p.assign(degr+1,0) ;
99 qp.assign(degr+1,0) ;
100 k.assign(degr+1,0) ;
101 qk.assign(degr+1,0) ;
102 svk.assign(degr+1,0) ;
103
104
105
106 for (i=0;i<=n;i++)
107 { p[i] = op[i]; }
108
109 do
110 {
111 if (n == 1)
112 {
113 zeror[degr-1] = -p[1]/p[0];
114 zeroi[degr-1] = 0.0;
115 n -= 1;
116 return degr - n ;
117 }
118 if (n == 2)
119 {
120 Quadratic(p[0],p[1],p[2],&zeror[degr-2],&zeroi[degr-2],
121 &zeror[degr-1],&zeroi[degr-1]);
122 n -= 2;
123 return degr - n ;
124 }
125
126
127
128 max = 0.0;
129 min = infin;
130 for (i=0;i<=n;i++)
131 {
132 x = std::fabs(p[i]);
133 if (x > max) { max = x; }
134 if (x != 0.0 && x < min) { min = x; }
135 }
136
137
138
139
140
141
142
143 sc = lo/min;
144
145 if ( ((sc <= 1.0) && (max >= 10.0))
146 || ((sc > 1.0) && (infin/sc >= max))
147 || ((infin/sc >= max) && (max >= 10)) )
148 {
149 if (!( sc != 0.0 ))
150 { sc = smalno ; }
151 l = (
G4int)(std::log(sc)/std::log(base) + 0.5);
152 factor = std::pow(base*1.0,l);
153 if (factor != 1.0)
154 {
155 for (i=0;i<=n;i++)
156 { p[i] = factor*p[i]; }
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
170 x = std::exp((std::log(-pt[n])-std::log(pt[0])) / (
G4double)n);
171
172
173
174 if (pt[n-1] != 0.0)
175 {
177 if (xm < x) { x = xm; }
178 }
179
180
181
182 while (1)
183 {
184 xm = x*0.1;
185 ff = pt[0];
187 { ff = ff*xm + pt[i]; }
188 if (ff <= 0.0) { break; }
189 x = xm;
190 }
191 dx = x;
192
193
194
195 while (std::fabs(dx/x) > 0.005)
196 {
197 ff = pt[0];
198 df = ff;
200 {
201 ff = ff*x + pt[i];
202 df = df*x + ff;
203 }
205 dx = ff/df;
206 x -= dx;
207 }
208 bnd = x;
209
210
211
212
216 k[0] = p[0];
219 zerok = (k[
n-1] == 0);
220 for(jj=0;jj<5;jj++)
221 {
223 if (!zerok)
224 {
225
226
227 t = -aa/cc;
228 for (i=0;i<nm1;i++)
229 {
231 k[j] = t*k[j-1]+p[j];
232 }
233 k[0] = p[0];
234 zerok = (std::fabs(k[n-1]) <= std::fabs(bb)*eta*10.0);
235 }
236 else
237 {
238 for (i=0;i<nm1;i++)
239 {
241 k[j] = k[j-1];
242 }
243 k[0] = 0.0;
244 zerok = (!(k[
n-1] != 0.0));
245 }
246 }
247
248
249
251 { temp[i] = k[i]; }
252
253
254
255 for (cnt = 0;cnt < 20;cnt++)
256 {
257
258
259
260
261
262 xxx = cosr*xx - sinr*yy;
263 yy = sinr*xx + cosr*yy;
264 xx = xxx;
265 sr = bnd*xx;
266 si = bnd*yy;
267 u = -2.0 * sr;
268 v = bnd;
269 ComputeFixedShiftPolynomial(20*(cnt+1),&nz);
270 if (nz != 0)
271 {
272
273
274
275
276
278 zeror[j] = szr;
279 zeroi[j] = szi;
282 { p[i] = qp[i]; }
283 if (nz != 1)
284 {
285 zeror[j+1] = lzr;
286 zeroi[j+1] = lzi;
287 }
288 break;
289 }
290 else
291 {
292
293
294
296 {
297 k[i] = temp[i];
298 }
299 }
300 }
301 }
302 while (nz != 0);
303
304
305
307}