Problem 56

Summary: In src/G4LineSection.cc divide by 0 and sqrt() from negative value are possible
Product: Geant4 Reporter: isupov
Component: geometryAssignee: Vladimir.Grichine
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 1.0   
Hardware: PC   
OS: Other   

Description isupov 2000-02-08 23:40:55 CET
1) If PntA so close to PntB, that VecAtoB.mag2() returns 0, we obtains
divide by zero in calculation inverse_square_distAB. If inverse_square_distAB
used only in G4LineSection::Dist() for unit_projection calc., , I think, we can
put it 0 without a problems:


  G4double sq_VecAB = VecAtoB.mag2();
  if (sq_VecAB == 0.0)
    inverse_square_distAB = 0.0;
  else
    inverse_square_distAB=1.0 / sq_VecAB;

-----------instead of -----------------------------

    inverse_square_distAB=1.0 / VecAtoB.mag2();

2) Because of we calculate subtract:

     dist_sq= sq_VecAZ -  unit_projection * inner_prod;

, we can obtain negative value in real calculations, where loss of precision
is possible. That leads to sqrt from negative value. I think, we need following
change:

     dist_sq= sq_VecAZ -  unit_projection * inner_prod;
     if (dist_sq < 0.0)
        dist_sq = 0.0;

--------------------instead of simple: --------------------

     dist_sq= sq_VecAZ -  unit_projection * inner_prod;


(Sorry fo non-diff "patches", but you web problem report form not so comfortable
for insertion from files :-(
Comment 1 Vladimir.Grichine 2000-03-24 08:44:59 CET
G4Exceptions were added in conditions resulting in
the problem mentioned.