Conversation
ndossche
reviewed
Sep 29, 2026
| memcpy(qptr, numerator->n_value, numerator->n_len + quot_scale); | ||
| (*quot)->n_sign = numerator->n_sign == divisor->n_sign ? PLUS : MINUS; | ||
| _bc_rm_leading_zeros(*quot); | ||
| if (bc_is_zero(*quot)) { |
Member
There was a problem hiding this comment.
Put the other n_sign assignment in this else branch
| *qptr++ = 0; | ||
| } | ||
| (*quot)->n_sign = numerator->n_sign == divisor->n_sign ? PLUS : MINUS; | ||
| if (bc_is_zero(*quot)) { |
…zero
A bc_num that is zero must carry PLUS, since bc_compare() orders by sign
first. The bc_divide() fast paths for a divisor of +/-1 or a power of ten,
bc_raise() with a positive exponent, and the Number add/sub/mul helpers
truncate to the requested scale and keep the operand sign, so
(new BcMath\Number('-0.001'))->div(1, 0) compares less than 0, is not
equal to 0, and makes sqrt() throw.
iliaal
force-pushed
the
fix/aph-bcmath-signed-zero-ikd-84-work
branch
from
September 29, 2026 12:25
95f2d36 to
2277e57
Compare
ndossche
approved these changes
Sep 29, 2026
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.
Several BcMath\Number operations kept the operand's negative sign when the result truncated to zero at the requested scale: the bc_divide() fast paths for a divisor of 1, -1 or a power of ten, bc_raise() with a positive exponent, and the add/sub/mul helpers. (new BcMath\Number('-0.001'))->div(1, 0) then compares less than 0, is not equal to 0, and makes sqrt() throw. String output already drops the sign of a zero, so the procedural functions are not affected.