File tree Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Expand file tree Collapse file tree 1 file changed +3
-5
lines changed Original file line number Diff line number Diff line change @@ -68,16 +68,14 @@ library CurveLib {
68
68
unchecked {
69
69
squaredB = absB * absB; // scale: 1e36
70
70
discriminant = squaredB + fourAC; // scale: 1e36
71
- sqrt = Math.sqrt (discriminant); // scale: 1e18
72
- sqrt = (sqrt * sqrt < discriminant) ? sqrt + 1 : sqrt;
71
+ sqrt = Math.sqrt (discriminant, Math.Rounding.Ceil); // scale: 1e18
73
72
}
74
73
} else {
75
74
// B^2 cannot be calculated directly at 1e18 scale without overflowing
76
75
uint256 scale = computeScale (absB); // calculate the scaling factor such that B^2 can be calculated without overflowing
77
76
squaredB = Math.mulDiv (absB / scale, absB, scale, Math.Rounding.Ceil);
78
77
discriminant = squaredB + fourAC / (scale * scale);
79
- sqrt = Math.sqrt (discriminant);
80
- sqrt = (sqrt * sqrt < discriminant) ? sqrt + 1 : sqrt;
78
+ sqrt = Math.sqrt (discriminant, Math.Rounding.Ceil);
81
79
sqrt = sqrt * scale;
82
80
}
83
81
@@ -86,7 +84,7 @@ library CurveLib {
86
84
// use the regular quadratic formula solution (-b + sqrt(b^2 - 4ac)) / 2a
87
85
x = Math.mulDiv (absB + sqrt, 1e18 , 2 * c, Math.Rounding.Ceil) + 1 ;
88
86
} else {
89
- // use the "citardauq" quadratic formula solution 2c / (-b + sqrt(b^2 - 4ac))
87
+ // use the "citardauq" quadratic formula solution 2c / (-b - sqrt(b^2 - 4ac))
90
88
x = (2 * C + (absB + sqrt - 1 )) / (absB + sqrt) + 1 ;
91
89
}
92
90
You can’t perform that action at this time.
0 commit comments