Last active
March 22, 2022 15:00
-
-
Save PaulRBerg/913bfcf82082fe5044a7938ad0c2880c to your computer and use it in GitHub Desktop.
Example consumer contract for PRBMathUD60x18 library: https://github.com/paulrberg/prb-math
This file contains hidden or 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
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity >=0.8.0; | |
import "@prb/math/contracts/PRBMathUD60x18.sol"; | |
contract UnsignedConsumer { | |
using PRBMathUD60x18 for uint256; | |
/// @notice Calculates x*1e18÷y while handling possible intermediary overflow. | |
function unsignedDiv(uint256 x, uint256 y) external pure returns (uint256 result) { | |
result = x.div(y); | |
} | |
/// @notice Calculates x*y÷1e18 while handling possible intermediary overflow. | |
/// @dev Try this with x = type(uint256).max and y = 5e17. | |
function unsignedMul(uint256 x, uint256 y) external pure returns (uint256 result) { | |
result = x.mul(y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment