Ejemplo n.º 1
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");
            }
        }