273{
277
279 G4int k, noReRoots = 0;
280
281 for( k = 0; k < 4; k++ ) { reRoot[k] =
DBL_MAX; }
282
283 if( p[0] != 1.0 )
284 {
285 for( k = 1; k < 5; k++) { p[k] = p[k]/p[0]; }
286 p[0] = 1.;
287 }
288 a3 = p[1];
289 a2 = p[2];
290 a1 = p[3];
291 a0 = p[4];
292
293
294
295 p[1] = -a2;
296 p[2] = a1*a3 - 4*a0;
297 p[3] = 4*a2*a0 - a1*a1 - a3*a3*a0;
298
300
301 for( k = 1; k < 4; k++ )
302 {
303 if( r[2][k] == 0. )
304 {
305 noReRoots++;
306 reRoot[k] = r[1][k];
307 }
309 }
311 for( k = 1; k < 4; k++ )
312 {
313 if ( reRoot[k] < y1 ) { y1 = reRoot[k]; }
314 }
315
316 R2 = 0.25*a3*a3 - a2 + y1;
317 b = 0.25*(4*a3*a2 - 8*a1 - a3*a3*a3);
318 c = 0.75*a3*a3 - 2*a2;
319 a = c - R2;
320 d = 4*y1*y1 - 16*a0;
321
322 if( R2 > 0.)
323 {
324 R = std::sqrt(R2);
325 D2 = a + b/R;
326 E2 = a - b/R;
327
328 if( D2 >= 0. )
329 {
330 D = std::sqrt(D2);
331 r[1][1] = -0.25*a3 + 0.5*R + 0.5*D;
332 r[1][2] = -0.25*a3 + 0.5*R - 0.5*D;
333 r[2][1] = 0.;
334 r[2][2] = 0.;
335 }
336 else
337 {
338 D = std::sqrt(-D2);
339 r[1][1] = -0.25*a3 + 0.5*R;
340 r[1][2] = -0.25*a3 + 0.5*R;
341 r[2][1] = 0.5*D;
342 r[2][2] = -0.5*D;
343 }
344 if( E2 >= 0. )
345 {
346 E = std::sqrt(E2);
347 r[1][3] = -0.25*a3 - 0.5*R + 0.5*E;
348 r[1][4] = -0.25*a3 - 0.5*R - 0.5*E;
349 r[2][3] = 0.;
350 r[2][4] = 0.;
351 }
352 else
353 {
354 E = std::sqrt(-E2);
355 r[1][3] = -0.25*a3 - 0.5*R;
356 r[1][4] = -0.25*a3 - 0.5*R;
357 r[2][3] = 0.5*E;
358 r[2][4] = -0.5*E;
359 }
360 }
361 else if( R2 < 0.)
362 {
363 R = std::sqrt(-R2);
366
367 r[1][1] = -0.25*a3 + 0.5*real(CD);
368 r[1][2] = -0.25*a3 - 0.5*real(CD);
369 r[2][1] = 0.5*R + 0.5*imag(CD);
370 r[2][2] = 0.5*R - 0.5*imag(CD);
373
374 r[1][3] = -0.25*a3 + 0.5*real(CE);
375 r[1][4] = -0.25*a3 - 0.5*real(CE);
376 r[2][3] = -0.5*R + 0.5*imag(CE);
377 r[2][4] = -0.5*R - 0.5*imag(CE);
378 }
379 else
380 {
381 if(d >= 0.)
382 {
383 D2 = c + std::sqrt(d);
384 E2 = c - std::sqrt(d);
385
386 if( D2 >= 0. )
387 {
388 D = std::sqrt(D2);
389 r[1][1] = -0.25*a3 + 0.5*R + 0.5*D;
390 r[1][2] = -0.25*a3 + 0.5*R - 0.5*D;
391 r[2][1] = 0.;
392 r[2][2] = 0.;
393 }
394 else
395 {
396 D = std::sqrt(-D2);
397 r[1][1] = -0.25*a3 + 0.5*R;
398 r[1][2] = -0.25*a3 + 0.5*R;
399 r[2][1] = 0.5*D;
400 r[2][2] = -0.5*D;
401 }
402 if( E2 >= 0. )
403 {
404 E = std::sqrt(E2);
405 r[1][3] = -0.25*a3 - 0.5*R + 0.5*E;
406 r[1][4] = -0.25*a3 - 0.5*R - 0.5*E;
407 r[2][3] = 0.;
408 r[2][4] = 0.;
409 }
410 else
411 {
412 E = std::sqrt(-E2);
413 r[1][3] = -0.25*a3 - 0.5*R;
414 r[1][4] = -0.25*a3 - 0.5*R;
415 r[2][3] = 0.5*E;
416 r[2][4] = -0.5*E;
417 }
418 }
419 else
420 {
421 ds = std::sqrt(-d);
424
425 r[1][1] = -0.25*a3 + 0.5*real(CD);
426 r[1][2] = -0.25*a3 - 0.5*real(CD);
427 r[2][1] = 0.5*R + 0.5*imag(CD);
428 r[2][2] = 0.5*R - 0.5*imag(CD);
429
432
433 r[1][3] = -0.25*a3 + 0.5*real(CE);
434 r[1][4] = -0.25*a3 - 0.5*real(CE);
435 r[2][3] = -0.5*R + 0.5*imag(CE);
436 r[2][4] = -0.5*R - 0.5*imag(CE);
437 }
438 }
439 return 4;
440}
std::complex< G4double > G4complex