2

Closed

Bug in right shift solved

description

In the end of OpHelper.cs there is an instruction with a bug:
DigitOpHelper.Shr(intX._digits, fullDigits, newLength, newInt._digits, 0, smallShift);
 
When the original number has 2 digits, the destination 1 digit, only part of the original is shifted (newLength equals 1 digit)
 
Here is the fix:
                uint length = newLength < intX._length ? newLength+1 : newLength;
                DigitOpHelper.Shr(intX._digits, fullDigits, length, newInt._digits, 0, smallShift);
 
I suggest more massive unit testing, like:
        // testing shl and shr
        for (int i = 1; i < 2000; i++)
        {
            IntX n = i;
            n = n << i;
            n = n >> i;
            Debug.Assert(n == i);
        }
Closed Jan 16, 2010 at 4:38 PM by Oyster
Thanks for reporting this issue, I have fixed it as suggested and added corresponding unit test. Fix is in release 0.9.3.

comments

leppie wrote Oct 9, 2009 at 7:12 PM

Thank you!!! I just spent a good few hours on this issue, and when I realized something was missing, I came to look. Seek and I did find :)

wrote Oct 9, 2009 at 7:12 PM

wrote Jan 16, 2010 at 4:38 PM

wrote Feb 14, 2013 at 2:28 AM

wrote May 16, 2013 at 7:34 AM