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
|
@@ -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;
|
|
115
|
-
if (
|
|
116
|
-
// `
|
|
117
|
-
|
|
118
|
-
|
|
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) {
|