Skip to content

Commit

Permalink
Comments on logarithm function graph speeds
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusWentz authored Sep 24, 2024
1 parent 83f5f73 commit 47c9a14
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions Contracts/pbrMathLogarithmTesting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ contract pbrMathLogarithmTesting {
// ud(1 ether) = x.log2() = x.log10() = 0
// Reverts with 999999999999999999

/// @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 = 10**(1).
result = x.log10();
}

/// @notice Calculates the binary logarithm of the given signed number.
function unsignedLog2WithTenEther() external pure returns (UD60x18 result) {
UD60x18 x = ud(10 ether);
Expand All @@ -22,11 +30,11 @@ contract pbrMathLogarithmTesting {
}

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

function unsignedLnWithEulersNumber() external pure returns (UD60x18 result) {
Expand All @@ -38,19 +46,23 @@ contract pbrMathLogarithmTesting {
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 log base 10 for the given signed number.
// Slowest growth logarithm function in pbr-math.
function unsignedLog10(UD60x18 x) external pure returns (UD60x18 result) {
result = x.log10();
}

/// @notice Calculates the log base 10 for the given signed number.
/// @notice Calculates the log base e for the given signed number.
// Slower growth than log2 but faster than log10 in pbr-math.
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();
/// @notice Calculates the log base 2 for the given signed number.
// Fastest growth logarithm function in pbr-math.
// Slower than the square root function in pbr-math.
function unsignedLog2(UD60x18 x) external pure returns (UD60x18 result) {
result = x.log2();
}

}

0 comments on commit 47c9a14

Please sign in to comment.