Repository: pcaversaccio/snekmate (language: python)

Issue:
♻️ Refactor the `is_negative` Function Into a Proper `sign` Function
### 🕓 Changelog

This PR refactors the `is_negative` function into a proper `sign` function. The function returns `-1` if `x < 0`, `0` if `x == 0`, and `1` if `x > 0`. For more details on finding the sign of a signed integer, please refer to: https://graphics.stanford.edu/~seander/bithacks.html#CopyIntegerSign. h/t @charles-cooper for spotting this improvement potential!

#### 🐶 Cute Animal Picture

![image](https://github.com/pcaversaccio/snekmate/assets/25297591/74152448-dbe8-45b3-9af9-6b79150ddde9)


Discussion / hints:

Fix patch:
diff --git a/.gas-snapshot b/.gas-snapshot
index 0fe4bf45..21ae5bf7 100644
--- a/.gas-snapshot
+++ b/.gas-snapshot
@@ -553,36 +553,36 @@ ERC721Test:testTransferFrom() (gas: 569632)
 ERC721Test:testTransferOwnershipNonOwner() (gas: 12612)
 ERC721Test:testTransferOwnershipSuccess() (gas: 52972)
 ERC721Test:testTransferOwnershipToZeroAddress() (gas: 15608)
-MathTest:testCbrtRoundDown() (gas: 41550)
-MathTest:testCbrtRoundUp() (gas: 42197)
+MathTest:testCbrtRoundDown() (gas: 41159)
+MathTest:testCbrtRoundUp() (gas: 41806)
 MathTest:testCeilDiv() (gas: 12481)
-MathTest:testFuzzCbrt(uint256,bool) (runs: 256, μ: 19455, ~: 19243)
+MathTest:testFuzzCbrt(uint256,bool) (runs: 256, μ: 19438, ~: 19252)
 MathTest:testFuzzCeilDiv(uint256,uint256) (runs: 256, μ: 8962, ~: 8979)
 MathTest:testFuzzInt256Average(int256,int256) (runs: 256, μ: 5683, ~: 5683)
-MathTest:testFuzzLog10(uint256,bool) (runs: 256, μ: 6968, ~: 6961)
-MathTest:testFuzzLog2(uint256,bool) (runs: 256, μ: 6846, ~: 6825)
-MathTest:testFuzzLog256(uint256,bool) (runs: 256, μ: 6847, ~: 6827)
-MathTest:testFuzzMulDiv(uint256,uint256,uint256) (runs: 256, μ: 13034, ~: 12781)
+MathTest:testFuzzLog10(uint256,bool) (runs: 256, μ: 6971, ~: 6961)
+MathTest:testFuzzLog2(uint256,bool) (runs: 256, μ: 6826, ~: 6803)
+MathTest:testFuzzLog256(uint256,bool) (runs: 256, μ: 6851, ~: 6827)
+MathTest:testFuzzMulDiv(uint256,uint256,uint256) (runs: 256, μ: 13038, ~: 12781)
 MathTest:testFuzzMulDivDomain(uint256,uint256,uint256) (runs: 256, μ: 10487, ~: 10570)
-MathTest:testFuzzSign(int256) (runs: 256, μ: 5528, ~: 5516)
-MathTest:testFuzzUint256Average(uint256,uint256) (runs: 256, μ: 5785, ~: 5785)
-MathTest:testFuzzWadCbrt(uint256) (runs: 256, μ: 18979, ~: 18650)
-MathTest:testFuzzWadExp(int256) (runs: 256, μ: 14494, ~: 14597)
-MathTest:testFuzzWadLn(int256) (runs: 256, μ: 16008, ~: 15758)
+MathTest:testFuzzSignum(int256) (runs: 256, μ: 5578, ~: 5570)
+MathTest:testFuzzUint256Average(uint256,uint256) (runs: 256, μ: 5763, ~: 5763)
+MathTest:testFuzzWadCbrt(uint256) (runs: 256, μ: 19002, ~: 18690)
+MathTest:testFuzzWadExp(int256) (runs: 256, μ: 14488, ~: 14597)
+MathTest:testFuzzWadLn(int256) (runs: 256, μ: 16004, ~: 15767)
 MathTest:testInt256Average() (gas: 12010)
 MathTest:testLog10RoundDown() (gas: 17685)
 MathTest:testLog10RoundUp() (gas: 18866)
 MathTest:testLog256RoundDown() (gas: 14561)
 MathTest:testLog256RoundUp() (gas: 14694)
 MathTest:testLog2RoundDown() (gas: 17351)
-MathTest:testLog2RoundUp() (gas: 17536)
+MathTest:testLog2RoundUp() (gas: 17514)
 MathTest:testMulDivDivisionByZero() (gas: 11226)
 MathTest:testMulDivOverflow() (gas: 11600)
 MathTest:testMulDivRoundDownLargeValues() (gas: 12763)
 MathTest:testMulDivRoundDownSmallValues() (gas: 7724)
 MathTest:testMulDivRoundUpLargeValues() (gas: 13096)
 MathTest:testMulDivRoundUpSmallValues() (gas: 7947)
-MathTest:testSign() (gas: 11385)
+MathTest:testSignum() (gas: 11419)
 MathTest:testUint256Average() (gas: 8298)
 MathTest:testWadCbrt() (gas: 39342)
 MathTest:testWadExp() (gas: 23595)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 908abe7d..00c4dd6d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
 
 - **Utility Functions**
   - [`Math`](https://github.com/pcaversaccio/snekmate/blob/v0.0.5/src/utils/Math.vy): Refactor the `is_negative` function into a proper `sign` function that returns the indication of the sign of a 32-byte signed integer. ([#187](https://github.com/pcaversaccio/snekmate/pull/187))
+  - [`Math`](https://github.com/pcaversaccio/snekmate/blob/v0.0.5/src/utils/Math.vy): Rename the recently added `sign` function to `signum` to avoid any ambiguity with cryptographic signing utility functions. ([#188](https://github.com/pcaversaccio/snekmate/pull/188))
 
 ### 👀 Full Changelog
 
diff --git a/src/utils/Math.vy b/src/utils/Math.vy
index 81f8fd91..8e8cbdb8 100644
--- a/src/utils/Math.vy
+++ b/src/utils/Math.vy
@@ -13,7 +13,7 @@
         - `uint256_average` (`external` `pure` function),
         - `int256_average` (`external` `pure` function),
         - `ceil_div` (`external` `pure` function),
-        - `sign` (`external` `pure` function),
+        - `signum` (`external` `pure` function),
         - `mul_div` (`external` `pure` function),
         - `log_2` (`external` `pure` function),
         - `log_10` (`external` `pure` function),
@@ -92,7 +92,7 @@ def ceil_div(x: uint256, y: uint256) -> uint256:
 
 @external
 @pure
-def sign(x: int256) -> int256:
+def signum(x: int256) -> int256:
     """
     @dev Returns the indication of the sign of a 32-byte signed integer.
     @notice The function returns `-1` if `x < 0`, `0` if `x == 0`, and `1`


Test patch:
diff --git a/test/utils/Math.t.sol b/test/utils/Math.t.sol
index c1fdc3af..ac7ccc46 100644
--- a/test/utils/Math.t.sol
+++ b/test/utils/Math.t.sol
@@ -154,16 +154,16 @@ contract MathTest is Test {
         math.ceil_div(1, 0);
     }
 
-    function testSign() public {
-        assertEq(math.sign(0), 0);
-        assertEq(math.sign(-1), -1);
-        assertEq(math.sign(-1 * -1), 1);
-        assertEq(math.sign(-1 * 100), -1);
-        assertEq(math.sign(0 * -1), 0);
-        assertEq(math.sign(int256(type(int16).min) * 2), -1);
-        assertEq(math.sign(int256(type(int16).max) * 2), 1);
-        assertEq(math.sign(type(int256).min + type(int16).max), -1);
-        assertEq(math.sign(type(int256).max - type(int16).max), 1);
+    function testSignum() public {
+        assertEq(math.signum(0), 0);
+        assertEq(math.signum(-1), -1);
+        assertEq(math.signum(-1 * -1), 1);
+        assertEq(math.signum(-1 * 100), -1);
+        assertEq(math.signum(0 * -1), 0);
+        assertEq(math.signum(int256(type(int16).min) * 2), -1);
+        assertEq(math.signum(int256(type(int16).max) * 2), 1);
+        assertEq(math.signum(type(int256).min + type(int16).max), -1);
+        assertEq(math.signum(type(int256).max - type(int16).max), 1);
     }
 
     function testMulDivDivisionByZero() public {
@@ -484,13 +484,13 @@ contract MathTest is Test {
         }
     }
 
-    function testFuzzSign(int256 x) public {
+    function testFuzzSignum(int256 x) public {
         if (x > 0) {
-            assertEq(math.sign(x), 1);
+            assertEq(math.signum(x), 1);
         } else if (x < 0) {
-            assertEq(math.sign(x), -1);
+            assertEq(math.signum(x), -1);
         } else {
-            assertEq(math.sign(x), 0);
+            assertEq(math.signum(x), 0);
         }
     }
 
diff --git a/test/utils/interfaces/IMath.sol b/test/utils/interfaces/IMath.sol
index a3adda4f..41a33c8c 100644
--- a/test/utils/interfaces/IMath.sol
+++ b/test/utils/interfaces/IMath.sol
@@ -11,7 +11,7 @@ interface IMath {
 
     function ceil_div(uint256 x, uint256 y) external pure returns (uint256);
 
-    function sign(int256 x) external pure returns (int256);
+    function signum(int256 x) external pure returns (int256);
 
     function mul_div(
         uint256 x,