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

math: fix big.int div, gcd and bitAnd edge-cases #11108

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

tiehuis
Copy link
Member

@tiehuis tiehuis commented Mar 10, 2022

Fixes #10932.

Disclaimer: The divmod change was fairly quick and I've yet to go through the algorithm again fully with the change in mind. The gcd/bitAnd change is fairly trivial.

@tiehuis
Copy link
Member Author

tiehuis commented Mar 10, 2022

To elaborate on the issues:

  • the gcd issue occurred when the gcd result exceeds a single limb and is reduced entirely in the main loop and not the single-limb processing at the end
  • the bitAnd was an incorrect assert which was being triggered when the limb_count(a) > limb_count(b) where a > b
  • the divmod issue occurs when a intermediate step results in a working value x which is normalized to 0, it's been a while since I reviewed this algorithm so no further comment yet

@andrewrk andrewrk merged commit 8bab1b4 into ziglang:master Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std.math.big.int panics (divFloor, gcd, bitAnd)
2 participants