-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
24 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
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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
library Packing { | ||
type Uint128x2 is bytes32; | ||
|
||
function asUint128x2(bytes32 packed) internal pure returns (Uint128x2) { | ||
return Uint128x2.wrap(packed); | ||
} | ||
|
||
function pack(uint128 high128, uint128 low128) internal pure returns (Uint128x2) { | ||
return Uint128x2.wrap(bytes32(bytes16(high128)) | bytes32(uint256(low128))); | ||
} | ||
|
||
function split(Uint128x2 packed) internal pure returns (uint128, uint128) { | ||
return (high(packed), low(packed)); | ||
} | ||
|
||
function high(Uint128x2 packed) internal pure returns (uint128) { | ||
return uint128(bytes16(Uint128x2.unwrap(packed))); | ||
} | ||
|
||
function low(Uint128x2 packed) internal pure returns (uint128) { | ||
return uint128(uint256(Uint128x2.unwrap(packed))); | ||
} | ||
} |