Skip to content

Commit

Permalink
Create pbrMathSquareRootTesting.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz authored Sep 24, 2024
1 parent f31f320 commit 298e413
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Contracts/pbrMathSquareRootTesting.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.26;

// Unsigned
import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";
// // Signed
// import { SD59x18, sd } from "@prb/math/src/SD59x18.sol";

contract pbrMathSquareRootTesting {

/// @notice Calculates the square root for the given signed number.
function unsignedSquareRootTestSmallValue() external pure returns (UD60x18 result) {
// 1 wei in uint256 is actually 1 ether in UD60x18 fixed point types.
UD60x18 x = ud(1);
// Returns 1000000000, since:
// 1 ether = 10**18 = (10**9)**2
result = x.sqrt();
}

/// @notice Calculates the square root for the given signed number.
function unsignedSquareRoot(UD60x18 x) external pure returns (UD60x18 result) {
result = x.sqrt();
}

}

0 comments on commit 298e413

Please sign in to comment.