Repository navigation
Fix #11154: integer / BigInt with a negative operand - #11155
Open
G26karthik wants to merge 1 commit into
Open
G26karthik wants to merge 1 commit into
G26karthik wants to merge 1 commit into
Conversation
opBinaryRight!"/" divided x by data.peekUlong(0), which is a ulong, so a negative x was converted to ulong before the division, and the sign of the BigInt was never used. Divide the magnitudes and apply the sign, as the % branch next to it already does.
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.
Rationale
integer / BigIntdividedxbydata.peekUlong(0), which is aulong, so a negativexwas converted toulongfirst and the sign of theBigIntwas ignored. For example-1000 / BigInt(10)returned-1717987019and1000 / BigInt(-10)returned100. It now divides the magnitudes and applies the sign, the same way the%branch next to it does, and still truncates toward zero like the built-in/.The unittest covers the three sign combinations with a negative operand,
long.min, quotients that truncate, and the unsigned case.One visible change: with an unsigned left operand and a negative
BigIntthe quotient is negative and does not fit inT, so it wraps, asint.min / BigInt(-1)already does.10u / BigInt(-5)now givescast(uint) -2instead of2.Feature request or issue tracking
Closes #11154.
Pre-review checklist
This fixes a reported issue, so I did not add a changelog entry.