-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Pierrick Turelier <pierrick@turelier.com>
- Loading branch information
1 parent
d8d3a9e
commit 29d0bf3
Showing
7 changed files
with
178 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity 0.8.23; | ||
|
||
library UIntMath { | ||
error InvalidUInt24(); | ||
|
||
error InvalidUInt40(); | ||
|
||
error InvalidUInt128(); | ||
|
||
error InvalidUInt192(); | ||
|
||
function safe24(uint256 n) internal pure returns (uint24) { | ||
if (n > type(uint24).max) revert InvalidUInt24(); | ||
return uint24(n); | ||
} | ||
|
||
function safe40(uint256 n) internal pure returns (uint40) { | ||
if (n > type(uint40).max) revert InvalidUInt40(); | ||
return uint40(n); | ||
} | ||
|
||
function safe128(uint256 n) internal pure returns (uint128) { | ||
if (n > type(uint128).max) revert InvalidUInt128(); | ||
return uint128(n); | ||
} | ||
|
||
function safe192(uint256 n) internal pure returns (uint192) { | ||
if (n > type(uint192).max) revert InvalidUInt192(); | ||
return uint192(n); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters