MCPcopy Create free account
hub / github.com/ElementsProject/elements / SaturatingAdd

Function SaturatingAdd

src/util/overflow.h:33–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32template <class T>
33[[nodiscard]] T SaturatingAdd(const T i, const T j) noexcept
34{
35 if constexpr (std::numeric_limits<T>::is_signed) {
36 if (i > 0 && j > std::numeric_limits<T>::max() - i) {
37 return std::numeric_limits<T>::max();
38 }
39 if (i < 0 && j < std::numeric_limits<T>::min() - i) {
40 return std::numeric_limits<T>::min();
41 }
42 } else {
43 if (std::numeric_limits<T>::max() - i < j) {
44 return std::numeric_limits<T>::max();
45 }
46 }
47 return i + j;
48}
49
50#endif // BITCOIN_UTIL_OVERFLOW_H

Callers 7

UpdateModifiedFeeMethod · 0.85
UpdateDescendantStateMethod · 0.85
UpdateAncestorStateMethod · 0.85
PrioritiseTransactionMethod · 0.85
TestAddMatrixOverflowFunction · 0.85
TestAddMatrixFunction · 0.85
TestAdditionOverflowFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestAddMatrixOverflowFunction · 0.68
TestAddMatrixFunction · 0.68
TestAdditionOverflowFunction · 0.68