keiwando/biginteger

Shift-left (`<<`) is broken

Closed this issue · 2 comments

Timwi commented

Not sure if this project is still in active development, but there appears to be an issue:

STEPS TO REPRODUCE

(BigInteger) (-1) << 1

EXPECTED RESULT

-2

ACTUAL RESULT

680564733841876926926749214863536422910

Timwi commented

I solved it for now by replacing the shift-left method with this one.

        public static BigInteger operator <<(BigInteger leftSide, int shiftCount)
        {
            if (leftSide == null)
            {
                throw new ArgumentNullException("leftSide");
            }

            return leftSide * Pow(2, shiftCount);
        }

Thanks for pointing that out! The problem should be fixed now. If I accidentally broke something else in the process, please let me know!