-
Notifications
You must be signed in to change notification settings - Fork 362
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
remove undefined bahavior #290
Conversation
Codecov Report
@@ Coverage Diff @@
## master #290 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 12 12
Lines 2887 2894 +7
=====================================
+ Hits 2887 2894 +7
Continue to review full report at Codecov.
|
aa41bae
to
75b4aae
Compare
I would like to point out that while the intent of this change is correct, the implementation fails in an edge case: assert(checked_multiply(2, std::numeric_limits<int>::min() / 2)); I would suggest the following change, which should work for both signed and unsigned types (the second branch is never called for them): if (a > 0 == b > 0) {
if ((std::numeric_limits<T>::max)() / absval(a) < absval(b))
return false;
}
else {
if ((std::numeric_limits<T>::min)() / absval(a) > -absval(b))
return false;
} |
I won't be able to get to it until tomorrow morning, if you want to wait I can do it then, otherwise go ahead. My one concern was the possibility of unused code warnings for the unsigned types. |
That's sooner than I could do it; I'm edging out a little time during the CoDaS-HEP workshop to catch up a little. Won't start having larger chunks of time till next week or so. |
… check for potential undefined behavior and wrapping.
…signed numbers and min val correctly. This involved adding to templates to clear up warnings
75b4aae
to
7e99462
Compare
I think this is ready to go now. with the additions recommended by @himikof |
change the checked_multiply function to not use undefined behavior to check for potential undefined behavior and wrapping.
See Issue #289