| Summary: | In src/G4LineSection.cc divide by 0 and sqrt() from negative value are possible | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | isupov |
| Component: | geometry | Assignee: | Vladimir.Grichine |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | 1.0 | ||
| Hardware: | PC | ||
| OS: | Other | ||
G4Exceptions were added in conditions resulting in the problem mentioned. |
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 :-(