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

Fix shl, shr & simplify isZero #133

Closed
wants to merge 1 commit into from
Closed

Conversation

konsumlamm
Copy link
Contributor

Now a: BigInt is zero if and only if a.limbs is empty. This simplifies isZero and reduces special cases to consider when consuming a BigInt.

While checking that all functions uphold this invariant, I noticed that shl and shr were buggy:

  • shl didn't check for zero, which allowed the user to construct BigInts with arbitrarily many zeros in its limbs, breaking an invariant
  • shr didn't check if the shift is too big, which could result in an exception

@konsumlamm
Copy link
Contributor Author

Division is making too much problems, perhaps I'll reconsider this once division has been rewritten.

@konsumlamm konsumlamm closed this Jul 23, 2023
@dlesnoff
Copy link
Contributor

If you have some failing checks, maybe this could be used for fixing the division algorithm. Do not hesitate to share these checks on the #123 issue.

@konsumlamm
Copy link
Contributor Author

The problems are that unsignedDivRem relies on 0 having a limb in a lot of places and trying to replace those cases manually is a pain. Some of these cases should go away once we have operations with SomeInteger operands, but eventually it should probably get rewritten.

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.

2 participants