Skip to content

Commit

Permalink
fix log base exp function comment and add ln(x) example
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz authored Sep 24, 2024
1 parent a719b31 commit 83f5f73
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions Contracts/pbrMathLogarithmTesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,38 @@ contract pbrMathLogarithmTesting {
function unsignedLog2WithTenEther() external pure returns (UD60x18 result) {
UD60x18 x = ud(10 ether);
// Returns 3.321928094887362334 ether, since:
// 10 = (3.321928094887362334)**2
// 10 = 2**(3.321928094887362334)
result = x.log2();
}

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

/// @notice Calculates the binary logarithm of the given signed number.
function unsignedLnWithEulersNumber() external pure returns (UD60x18 result) {
UD60x18 x = ud(2718281828459045260);
// Returns 1 ether, since:
// e = e**(1)
// which is rougly about:
// 2.718281828459045260**(1).
result = x.ln();
}

/// @notice Calculates the log base 2 for the given signed number.
function unsignedLog2(UD60x18 x) external pure returns (UD60x18 result) {
result = x.log2();
}

/// @notice Calculates the binary logarithm of the given signed number.
/// @notice Calculates the log base 10 for the given signed number.
function unsignedLn(UD60x18 x) external pure returns (UD60x18 result) {
result = x.ln();
}

/// @notice Calculates the log base 10 for the given signed number.
function unsignedLog10(UD60x18 x) external pure returns (UD60x18 result) {
result = x.log10();
}
Expand Down

0 comments on commit 83f5f73

Please sign in to comment.