-
-
Notifications
You must be signed in to change notification settings - Fork 829
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
Fix wrong integer division where rounding up was intended #1254
Fix wrong integer division where rounding up was intended #1254
Conversation
8bb2785
to
126b41a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
1dadfe4
to
2103e16
Compare
I've updated the function again. I managed to leave an error for negative numbers and ran missed it by running tests that haven't yet been recompiled with updated code. |
2103e16
to
51e6f6a
Compare
it's funny how an apparently simple function like this still has so many entries on StackOverflow and many different answers. |
51e6f6a
to
87c6537
Compare
The intention here likely was to get floating-point division result and round it upwards. However, the division was performed with integer arguments, fractional part was lost and thus std::ceil did nothing.
87c6537
to
2caea25
Compare
The intention in cases like
std::ceil(a / b)
(wherea
andb
are integers) likely was to get floating-point division result and round it upwards. However, the division was performed with integer arguments, fractional part was lost and thusstd::ceil
did nothing. This PR introduces a separate function to perform such integer division and fixes the buggy cases.If the original intention was wrong, this PR will break behavior. According to my limited understanding of the code the original intention was correct.
A subsequent PR will change all similar cases where we currently do
int(std::ceil(double(a) / double(b)))
to usedivideRoundUp()
.