Skip to content

Commit

Permalink
Create pbrMathLogTesting.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz authored Sep 24, 2024
1 parent d58054d commit 6dd4275
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Contracts/pbrMathLogTesting.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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 pbrMathLogTesting {

/// @notice Calculates the binary logarithm of the given signed number.
/// @dev Try this with x = 128e18.
function unsignedLog2WithTenEther() external pure returns (UD60x18 result) {
UD60x18 x = ud(10 ether);
// Returns 3.321928094887362334 ether, since:
// 10 ether = 2**(3.321928094887362334 ether)
result = x.log2();
}

/// @notice Calculates the binary logarithm of the given signed number.
/// @dev Try this with x = 128e18.
function unsignedLog10WithTenEther() external pure returns (UD60x18 result) {
UD60x18 x = ud(10 ether);
// Returns 1 ether, since:
// 10 ether = 10**(1 ether).
result = x.log10();
}

/// @notice Calculates the binary logarithm of the given signed number.
/// @dev Try this with x = 128e18.
function unsignedLog2(UD60x18 x) external pure returns (UD60x18 result) {
result = x.log2();
}

/// @notice Calculates the binary logarithm of the given signed number.
/// @dev Try this with x = 128e18.
function unsignedLog10(UD60x18 x) external pure returns (UD60x18 result) {
result = x.log10();
}

}

0 comments on commit 6dd4275

Please sign in to comment.