Skip to content
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

util: Add SaturatingAdd helper #24224

Merged
merged 1 commit into from Feb 21, 2022
Merged

util: Add SaturatingAdd helper #24224

merged 1 commit into from Feb 21, 2022

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Feb 1, 2022

@laanwj
Copy link
Member

laanwj commented Feb 3, 2022

Concept ACK. This seems useful, hopefully C++ will have built-ins for explicitly saturating/wrapping/checked arithmetic like rust some day. But until then…

@maflcko
Copy link
Member Author

maflcko commented Feb 3, 2022

saturating/wrapping/checked arithmetic like rust

I wasn't aware that rust has those built-in. Mind sharing a link to the docs?

@maflcko
Copy link
Member Author

maflcko commented Feb 3, 2022

Copy link
Contributor

@klementtan klementtan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review ACK fa90189

@@ -28,4 +28,22 @@ template <class T>
return i + j;
}

template <class T>
[[nodiscard]] T SaturatingAdd(const T i, const T j) noexcept
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa90189

src/test/util_tests.cpp Show resolved Hide resolved
@maflcko
Copy link
Member Author

maflcko commented Feb 21, 2022

Added a test. Should be trivial to re-ACK with git range-diff bitcoin-core/master fa90189cbf faa7d8a3f7

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK faa7d8a

@klementtan
Copy link
Contributor

klementtan commented Feb 21, 2022

reACK faa7d8a

@maflcko maflcko merged commit e44423c into bitcoin:master Feb 21, 2022
@maflcko maflcko deleted the 2201-satadd branch February 21, 2022 14:52
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Feb 22, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Feb 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants