Repository navigation
Fix integer division in TMath::IsInside - #23474
Conversation
|
Can you extend test a bit? |
Test Results 24 files 24 suites 4d 1h 33m 1s ⏱️ For more details on these failures, see this check. Results for commit 1624710. ♻️ This comment has been updated with latest results. |
Thanks. I’ve expanded the regression test to cover many points across the diamond rather than a single point. One question: would you also like me to add a few targeted cases for I can add those if you think they would be useful. |
Implemented the expanded regression test as suggested. It now compares the |
agheata
left a comment
There was a problem hiding this comment.
This clearly improves on the previous version based on integer division. The calculation is exact provided the intermediate differences and cross products fit in Long64_t. However, even Int_t coordinates can overflow the products:
constexpr Int_t a = 1600000000;
Int_t x[] = {-a, -a, a, a};
Int_t y[] = {-a, a, a, -a};
TMath::IsInside(1500000000, 0, 4, x, y); // expected trueThe point is strictly inside the square, but the tested build returns false. One product is −9,920,000,000,000,000,000, outside the signed 64-bit range, causing undefined behavior.
IMHO this is mergeable with a code comment documenting the overflow limitation, since it correctly handles typical bounded coordinate ranges. Runtime overflow checks may add overhead; their cost compared with using double would need benchmarking.
|
With previous implementation we got 50% of failures with "normal" values from range |
|
I let @hageboeck review and approve PR |
|
can I help with something? @linev @agheata @hageboeck @ktf |
|
For the record, I am not sure why I am in the loop. |
my bad |
|
I reopen PR to restart CI |
linev
left a comment
There was a problem hiding this comment.
I think, new implementation is much better than before.
So let merge it!
Description
Fix integer division in
TMath::IsInside()whenInt_tcoordinates are used.Problem
The current implementation calculates the edge intersection as:
fixes ##23450