Skip to content

Commit

Permalink
Update pbrMathLogarithmTesting.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz authored Sep 24, 2024
1 parent 298e413 commit a719b31
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Contracts/pbrMathLogarithmTesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,33 @@ import { UD60x18, ud } from "@prb/math/src/UD60x18.sol";

contract pbrMathLogarithmTesting {

// For log2 and log10:
// Min input value for ud(x) is = 1 ether = 1000000000000000000
// ud(1 ether) = x.log2() = x.log10() = 0
// Reverts with 999999999999999999

/// @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)
// 10 = (3.321928094887362334)**2
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).
// 10 = 1**(10).
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();
}
Expand Down

0 comments on commit a719b31

Please sign in to comment.