-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: safe divide #3253
feat: safe divide #3253
Conversation
Is an exception really better than an FPE? |
At least it is not undefined behaviour. Alternatively I thought about Third option could be using something like in |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3253 +/- ##
==========================================
+ Coverage 47.65% 47.66% +0.01%
==========================================
Files 507 507
Lines 29205 29212 +7
Branches 14010 14011 +1
==========================================
+ Hits 13917 13924 +7
Misses 5264 5264
Partials 10024 10024 ☔ View full report in Codecov by Sentry. |
📊: Physics performance monitoring for a5454d7physmon summary
|
Well but it is the kind of UB which always behaves nicely in reality in my experience 😄 I think if we go hard on all UB we have to change quite some code in Acts The idea of the other helpers was to return optional values in case of a problem. But I have a hard time seeing the use case here |
I'm also not entirely convinced. With the FPE monitoring, we have the ability to fix faulty operations only where they occur. In case of the ROOT writers, I think we'd either want to manually handle them, in which case an exception is not necessarily the best way to go, or fix the underlying cause for the FPE. The optional return imo has little benefit over checking the denominator manually at the call site. Also, is FLTDIV even UB? I thought it always results in EDIT: I don't think it's UB. IEEE 754 specifies that any nonzero float divided by zero is +- infinity. So imo we should really only work around that if it causes concrete issues. |
In conclusion, I think I'm okay having this and using it in cases where we've observed FPE FLTDIVs. But I would not start applying these functions everywhere without a reason. |
sounds good to me. I made this, since I had the concrete case in the linked PR :) |
I am still not convinced by this. The only use we have is in #3255 and it looks to me like treating symptoms. Instead of returning a valid Comparing a potential use how we would do it today
Against the proposed solution
We lose lose the condition and we lose the physical cutoff value. |
Currently not needed anymore, since the only usecase was abandoned. |
Prevents FPEs by giving a good estimate, when i comes to a potentially dangerous division.
Example use case is the
pathCorrection
calculation for thecylinderSurface
. We do not want to fail the navigation, and instead give an good estimate for the correction: