-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ApproxRoot Infinite Looping #7038
Comments
/cc @sunnya97 :( |
I'd propose to remove the feature in |
Fine by me -- feel free to remove entirely. |
@karzak Are you using this function? |
No - this doesn't have an impact on Kava. |
I understand why it would be removed, but is there the possibility of restricting it to a known range of valid inputs or a larger error tolerance rather than removing it completely? Or maybe an alternative approach can be found? It is currently used by the bonds module. In any case, I'm happy to see the bug get squished. |
As discussed with @migueldingli1997, he'll take a stab at this |
I'm thinking that with any implementation with no hard limit, there might always be the possibility that we get an infinite loop. So in my opinion the simplest solution without messing too much with the current code is to add an extra 'maximum number of iterations' argument which puts a hard limit on the looping. From my experimentation, it seems typically the number of iterations required is in the 10's, so maybe a hard limit that could be used would be 100. Will open a PR with this solution. |
Added a maximum number of iterations (100) to ApproxRoot (and ApproxSqrt) to serve as a hard limit on the number of iterations that the algorithm performs. If the answer converges before the maximum iterations, it returns immediately. Otherwise, if the answer never converges enough to satisfy the primary loop condition, the looping stops after a hundred iterations. Closes: #7038 Co-authored-by: Alessio Treglia <quadrispro@ubuntu.com>
Added a maximum number of iterations (100) to ApproxRoot (and ApproxSqrt) to serve as a hard limit on the number of iterations that the algorithm performs. If the answer converges before the maximum iterations, it returns immediately. Otherwise, if the answer never converges enough to satisfy the primary loop condition, the looping stops after a hundred iterations. Closes: #7038
Added a maximum number of iterations (100) to ApproxRoot (and ApproxSqrt) to serve as a hard limit on the number of iterations that the algorithm performs. If the answer converges before the maximum iterations, it returns immediately. Otherwise, if the answer never converges enough to satisfy the primary loop condition, the looping stops after a hundred iterations. Closes: #7038 Co-authored-by: Miguel Dingli <migueldingli97@gmail.com>
Summary of Bug
Infinite loop when supplying small values to the
Dec.ApproxRoot()
function, most likely because the SmallestDec boundary is never satisfied. Example input:ApproxRoot(NewDecWithPrec(10000000000, 18), 3)
Version
Commit:
6a7cf4442e340b1878b28552778e42d3c6285624
(master as of writing)Steps to Reproduce
Add the following test case to
TestApproxRoot
function intypes/decimal_test.go
:{NewDecWithPrec(10000000000, 18), 3, MustNewDecFromStr("0")},
For Admin Use
The text was updated successfully, but these errors were encountered: