solidity-math-utils 1.5.0 → 1.6.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "solidity-math-utils",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Solidity Mathematical Utilities",
5
5
  "repository": {
6
6
  "type": "git",
@@ -111,13 +111,13 @@ library FractionMath {
111
111
  * @return The estimated ratio denominator
112
112
  */
113
113
  function estimatedRatio(uint256 n, uint256 d, uint256 scale) private pure returns (uint256, uint256) { unchecked {
114
- uint256 x = MAX_VAL / scale; // `MAX_VAL >= scale` hence `x >= 1`
115
- if (x < n) {
116
- // `x < n <= MAX_VAL` hence `x < MAX_VAL` hence `x + 1` is safe
117
- // `x >= 1` hence `n / (x + 1) < MAX_VAL` hence `n / (x + 1) + 1` is safe
118
- uint256 y = n / (x + 1) + 1;
119
- n /= y; // we can now safely compute `n * scale`
114
+ uint256 x = MAX_VAL / scale;
115
+ if (n > x) {
116
+ // `n * scale` will overflow
117
+ uint256 y = (n - 1) / x + 1;
118
+ n /= y;
120
119
  d /= y;
120
+ // `n * scale` will not overflow
121
121
  }
122
122
 
123
123
  if (n < d) {