Skip to content

util: Add SaturatingAdd helper - #24224

Merged
maflcko merged 1 commit into
bitcoin:masterfrom
maflcko:2201-satadd
Feb 21, 2022
Merged

maflcko merged 1 commit into
bitcoin:masterfrom
maflcko:2201-satadd

Conversation

@maflcko

@maflcko maflcko commented Feb 1, 2022

Copy link
Copy Markdown
Member

@laanwj

laanwj commented Feb 3, 2022 •

Copy link
Copy Markdown
Member

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

maflcko commented Feb 3, 2022

Copy link
Copy Markdown
Member Author

saturating/wrapping/checked arithmetic like rust

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

@klementtan klementtan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review ACK fa90189cbfe10552f94fdaa8607cdd5a10341ced

Comment thread src/util/overflow.h Outdated

Copy link
Copy Markdown
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
Copy Markdown
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.

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK fa90189cbfe10552f94fdaa8607cdd5a10341ced

Comment thread src/test/util_tests.cpp Resolved
@maflcko

maflcko commented Feb 21, 2022

Copy link
Copy Markdown
Member Author

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

@vasild vasild left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK faa7d8a

@klementtan

klementtan commented Feb 21, 2022 •

Copy link
Copy Markdown
Contributor

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
@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.

5 participants