-
Notifications
You must be signed in to change notification settings - Fork 38.7k
util: Add SaturatingAdd helper #24224
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
Conversation
|
Concept ACK. This seems useful, hopefully C++ will have built-ins for explicitly saturating/wrapping/checked arithmetic like rust some day. But until then… |
I wasn't aware that rust has those built-in. Mind sharing a link to the docs? |
|
Oh, I see. By default rust will panic, but there are https://doc.rust-lang.org/std/num/index.html: |
klementtan
left a comment
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.
Code Review ACK fa90189cbfe10552f94fdaa8607cdd5a10341ced
src/util/overflow.h
Outdated
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.
Out of curiosity, any reason you didn't constexpr this function?
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.
Outside of unit tests I don't think this will ever be called in a context that would be constexpr.
vasild
left a comment
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.
ACK fa90189cbfe10552f94fdaa8607cdd5a10341ced
|
Added a test. Should be trivial to re-ACK with |
vasild
left a comment
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.
ACK faa7d8a
|
reACK faa7d8a |
Seems good to have this in the repo, as it might be needed to write cleaner code. For example: