Allocate minimum necessary digits for quotient and remainder#326
Closed
tompng wants to merge 2 commits into
Closed
Allocate minimum necessary digits for quotient and remainder#326tompng wants to merge 2 commits into
tompng wants to merge 2 commits into
Conversation
tompng
commented
May 24, 2025
| word_r = r->MaxPrec; | ||
|
|
||
| if (word_a >= word_r) goto space_error; | ||
| if (word_a >= word_r || word_b + word_c - 2 >= word_r) goto space_error; |
Member
Author
There was a problem hiding this comment.
There are two more goto space_error in this function.
One is on L6218
ind_r = ind_c + ind_b;
if (ind_r >= word_r) goto space_error;And another in L6253
ind_r = b->Prec + ind_c - 1; // L6242
ind_r = b->Prec + ind_c; // L6250 (ind_c + 1 < word_c is ensured in L6247)
if (ind_r >= word_r) goto space_error;Both has the same requirement: (word_b-1) + (word_c-1) < word_r
4ed8610 to
65922a8
Compare
tompng
commented
May 24, 2025
Comment on lines
+1857
to
1860
| mx = ((a_prec > b_prec) ? a_prec : b_prec) + BIGDECIMAL_DOUBLE_FIGURES; | ||
|
|
||
| if (2*BIGDECIMAL_DOUBLE_FIGURES > mx) | ||
| mx = 2*BIGDECIMAL_DOUBLE_FIGURES; |
Member
Author
There was a problem hiding this comment.
Precision was max(a_prec*2, b_prec*2, 32).
I think we normally need max(a_prec, b_prec) + extra precision, and the extra part was ≧16 before.
Fixes wrong calculation of quotient and remainder precision in `a / b` division. Precision of quotient is sufficient enough with `[a_prec,b_prec].max+extra`. Required remainder allocation size can be calculated from requirements of VpDivd. VpDivd requires `r_maxprec > a_prec` and `r_maxprec > b_prec+c_maxprec-2`.
65922a8 to
952f481
Compare
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #220 and #222
Fixes wrong calculation of quotient and remainder precision in
a / bdivision.Precision of quotient is sufficient enough with
[a_prec,b_prec].max+extra.Required remainder allocation size can be calculated from requirements of VpDivd.
VpDivd requires
r_maxprec > a_precandr_maxprec > b_prec+c_maxprec-2.