Closed konsumlamm closed 1 year ago
Division is making too much problems, perhaps I'll reconsider this once division has been rewritten.
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.
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.
Now
a: BigInt
is zero if and only ifa.limbs
is empty. This simplifiesisZero
and reduces special cases to consider when consuming aBigInt
.While checking that all functions uphold this invariant, I noticed that
shl
andshr
were buggy:shl
didn't check for zero, which allowed the user to constructBigInt
s with arbitrarily many zeros in its limbs, breaking an invariantshr
didn't check if the shift is too big, which could result in an exception