We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6895647 commit 7ab1afaCopy full SHA for 7ab1afa
src/math/LibSafeRange.sol
@@ -0,0 +1,20 @@
1
+//SPDX-License-Identifier: MIT
2
+pragma solidity ^0.8.0;
3
+
4
+library LibSafeRange {
5
+ function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
6
+ unchecked {
7
+ c = a + b;
8
+ if (c < a) return type(uint256).max;
9
+ }
10
11
12
+ /**
13
+ * @dev Returns value of a + b; in case result is larger than upperbound, upperbound is returned.
14
+ */
15
+ function addWithUpperbound(uint256 a, uint256 b, uint256 ceil) internal pure returns (uint256 c) {
16
+ if (a > ceil || b > ceil) return ceil;
17
+ c = add(a, b);
18
+ if (c > ceil) return ceil;
19
20
+}
0 commit comments