Skip to content
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

improve sdk.Dec ApproxRoot #12296

Open
4 tasks
catShaark opened this issue Jun 17, 2022 · 0 comments
Open
4 tasks

improve sdk.Dec ApproxRoot #12296

catShaark opened this issue Jun 17, 2022 · 0 comments
Labels
C:math Component: Math S:proposed

Comments

@catShaark
Copy link
Contributor

Problem Definition

As discussed in 12229, we find some problems with ApproxRoot here:

  • ApproxRoot behavior is imo unsafe, it needs to be returning an error or a flag at minimum, if it can't converege within max iterations, so the caller doesn't have incorrect expectations.
  • ApproxRoot will panic "out of bound" for very large sdk.Dec even if it has smaller bit len than maxDecBitLen. I think this is because we're using Newton-Raphson method with the initial guess of 1, which in cases of large input, makes the second guess far far exceeds the actual root value, causing the "out of bound".
  • There should be different dedicated functions for square root and cube root.
  • There's inaccuracy due to not enough precision. Tho this will likely be solved by moving to APD which the sdk team is planning/ working on, so we leave this one out.

Proposal

  • Make 2 new functions for square root and cube root using different logic than ApproxRoot.
  • Change ApproxRoot logic so that it doesn't panic out of bound for very large valid sdk.Dec. We can fix this by including some condition checks for the guesses in the function.
  • Return an error or a flag in case ApproxRoot fails to return the correct result.

For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@tac0turtle tac0turtle added S:proposed C:math Component: Math labels Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:math Component: Math S:proposed
Projects
None yet
Development

No branches or pull requests

2 participants