From 47c9a149c9a62a86df211c433656b63ec38bf713 Mon Sep 17 00:00:00 2001 From: MarcusWentz <52706599+MarcusWentz@users.noreply.github.com> Date: Tue, 24 Sep 2024 07:01:54 -0400 Subject: [PATCH] Comments on logarithm function graph speeds --- Contracts/pbrMathLogarithmTesting.sol | 34 ++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Contracts/pbrMathLogarithmTesting.sol b/Contracts/pbrMathLogarithmTesting.sol index e9283c6..19feccb 100644 --- a/Contracts/pbrMathLogarithmTesting.sol +++ b/Contracts/pbrMathLogarithmTesting.sol @@ -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); @@ -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) { @@ -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(); } }