solidity-math-utils 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/project/contracts/AdvancedMath.sol +1 -1
- package/project/contracts/AnalyticMath.sol +1 -1
- package/project/contracts/BondingCurve.sol +1 -1
- package/project/contracts/DynamicCurve.sol +1 -1
- package/project/contracts/FractionMath.sol +1 -1
- package/project/contracts/IntegralMath.sol +9 -21
- package/project/contracts/common/Uint256.sol +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solidity-math-utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Solidity Mathematical Utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@nomiclabs/hardhat-truffle5": "2.1.0",
|
|
22
22
|
"@nomiclabs/hardhat-web3": "2.1.0",
|
|
23
23
|
"decimal.js": "10.6.0",
|
|
24
|
-
"hardhat": "2.
|
|
25
|
-
"solidity-coverage": "0.8.
|
|
24
|
+
"hardhat": "2.28.0",
|
|
25
|
+
"solidity-coverage": "0.8.17"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
|
|
2
|
-
pragma solidity 0.8.
|
|
2
|
+
pragma solidity ^0.8.33;
|
|
3
3
|
|
|
4
4
|
import "./common/Uint256.sol";
|
|
5
5
|
|
|
@@ -8,26 +8,11 @@ library IntegralMath {
|
|
|
8
8
|
* @dev Compute the largest integer smaller than or equal to the binary logarithm of `n`
|
|
9
9
|
*/
|
|
10
10
|
function floorLog2(uint256 n) internal pure returns (uint8) { unchecked {
|
|
11
|
-
uint8
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// at most 8 iterations
|
|
15
|
-
while (n > 1) {
|
|
16
|
-
n >>= 1;
|
|
17
|
-
res += 1;
|
|
18
|
-
}
|
|
11
|
+
uint8 x = 0;
|
|
12
|
+
if (n > 0) {
|
|
13
|
+
assembly {x := not(clz(n))}
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
// exactly 8 iterations
|
|
22
|
-
for (uint8 s = 128; s > 0; s >>= 1) {
|
|
23
|
-
if (n >= 1 << s) {
|
|
24
|
-
n >>= s;
|
|
25
|
-
res |= s;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return res;
|
|
15
|
+
return x;
|
|
31
16
|
}}
|
|
32
17
|
|
|
33
18
|
/**
|
|
@@ -218,8 +203,11 @@ library IntegralMath {
|
|
|
218
203
|
uint8 zwhn = floorLog2(zwh);
|
|
219
204
|
while (xyhn > zwhn) {
|
|
220
205
|
uint8 n = xyhn - zwhn - 1;
|
|
206
|
+
uint256 zwhshl = zwh << n;
|
|
207
|
+
uint256 zwlshl = zwl << n;
|
|
208
|
+
uint256 zwlshr = zwl >> (256 - n);
|
|
221
209
|
res += 1 << n; // set `res = res + 2 ^ n`
|
|
222
|
-
(xyh, xyl) = sub512Ex(xyh, xyl,
|
|
210
|
+
(xyh, xyl) = sub512Ex(xyh, xyl, zwhshl | zwlshr, zwlshl); // set `xy = xy - zw * 2 ^ n`
|
|
223
211
|
xyhn = floorLog2(xyh);
|
|
224
212
|
}
|
|
225
213
|
}
|