示例#1
0
        Sub(Digits a, Digits b, Digits c, Digits mod, int n)
        {
            Debug.Assert(n > 0, "internal error");
            Digit alead = a[n - 1], blead = b[n - 1], mlead = mod[n - 1];
            int   itest;

            if (alead == blead)
            {
                itest = Digits.Compare(a, b, n - 1);
            }
            else
            {
                itest = alead < blead ? -1 : +1;
            }
            if (itest < 0)
            {
                if (blead >= mlead)
                {
                    ValidateData(b, mod, n);
                }
                int carry = Digits.AddSub(a, mod, b, c, n);
                Debug.Assert(carry == 0, "internal error");
            }
            else
            {
                if (alead >= mlead)
                {
                    Debug.Assert(false, "untested code");
                    ValidateData(a, mod, n);
                }
                uint borrow = Digits.Sub(a, b, c, n);
                Debug.Assert(borrow == 0, "internal error");
            }
        }
示例#2
0
        Add(Digits a, Digits b, Digits c, Digits mod, int n)
        {
            Debug.Assert(n != 0, "internal error");
            Digit alead = a[n - 1], blead = b[n - 1], mlead = mod[n - 1];

            if (alead >= mlead)
            {
                ValidateData(a, mod, n);
            }
            if (blead >= mlead)
            {
                ValidateData(b, mod, n);
            }
            int test;

            if (blead > mlead - alead)
            {
                test = +1;
            }
            else if (mlead - alead - blead > 1)
            {
                test = -1;
            }
            else
            {
                test = Digits.CompareSum(a, b, mod, n);
            }
            if (test >= 0)
            {
                int carry = Digits.AddSub(a, b, mod, c, n);
                Debug.Assert(carry == 0, "internal error");
            }
            else
            {
                uint carry = Digits.Add(a, b, c, n);
                Debug.Assert(carry == 0, "internal error");
            }
        }