当前位置: 首页>>代码示例>>C#>>正文


C# BigInteger.AssertValid方法代码示例

本文整理汇总了C#中BigInteger.AssertValid方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.AssertValid方法的具体用法?C# BigInteger.AssertValid怎么用?C# BigInteger.AssertValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BigInteger的用法示例。


在下文中一共展示了BigInteger.AssertValid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DivRem

            public uint DivRem(BigInteger bi) {
                AssertValid();
                bi.AssertValid();
                Debug.Assert((object)this != (object)bi);

                int idx, cu;
                uint uQuo, wCarry;
                int wT;
                uint uT, uHi, uLo;

                cu = bi.length;
                Debug.Assert(length <= cu);
                if (length < cu) {
                    return 0;
                }

                // Get a lower bound on the quotient.
                uQuo = (uint)(digits[cu - 1] / (bi.digits[cu - 1] + 1));
                Debug.Assert(uQuo >= 0 && uQuo <= 9);

                // Handle 0 and 1 as special cases.
                switch (uQuo) {
                case 0:
                    break;
                case 1:
                    Subtract(bi);
                    break;
                default:
                    uHi = 0;
                    wCarry = 1;
                    for (idx = 0; idx < cu; idx++) {
                        Debug.Assert(0 == wCarry || 1 == wCarry);

                        // Compute the product.
                        uLo = MulU(uQuo, bi.digits[idx], out uT);
                        uHi = uT + AddU(ref uLo, uHi);

                        // Subtract the product. See note in BigInteger.Subtract.
                        if (0 != uLo || 0 == wCarry) {
                            wCarry = AddU(ref digits[idx], ~uLo + wCarry);
                        }
                    }
                    Debug.Assert(1 == wCarry);
                    Debug.Assert(idx == cu);

                    // Trim off zeros.
                    while (--idx >= 0 && 0 == digits[idx]) {
                    }
                    length = idx + 1;
                    break;
                }

                if (uQuo < 9 && (wT = CompareTo(bi)) >= 0) {
                    // Quotient was off too small (by one).
                    uQuo++;
                    if (0 == wT) {
                        length = 0;
                    } else {
                        Subtract(bi);
                    }
                }
                Debug.Assert(CompareTo(bi) < 0);

                return uQuo;
            }
开发者ID:uQr,项目名称:referencesource,代码行数:65,代码来源:XPathConvert.cs

示例2: Add

            public void Add(BigInteger bi) {
                AssertValid();
                bi.AssertValid();
                Debug.Assert((object)this != (object)bi);

                int idx, cuMax, cuMin;
                uint wCarry;

                if ((cuMax = length) < (cuMin = bi.length)) {
                    cuMax = bi.length;
                    cuMin = length;
                    Ensure(cuMax + 1);
                }

                wCarry = 0;
                for (idx = 0; idx < cuMin; idx++) {
                    if (0 != wCarry) {
                        wCarry = AddU(ref digits[idx], wCarry);
                    }
                    wCarry += AddU(ref digits[idx], bi.digits[idx]);
                }

                if (length < bi.length) {
                    for ( ; idx < cuMax; idx++) {
                        digits[idx] = bi.digits[idx];
                        if (0 != wCarry) {
                            wCarry = AddU(ref digits[idx], wCarry);
                        }
                    }
                    length = cuMax;
                } else {
                    for ( ; 0 != wCarry && idx < cuMax; idx++) {
                        wCarry = AddU(ref digits[idx], wCarry);
                    }
                }

                if (0 != wCarry) {
                    Ensure(length + 1);
                    digits[length++] = wCarry;
                }
                AssertValid();
            }
开发者ID:uQr,项目名称:referencesource,代码行数:42,代码来源:XPathConvert.cs

示例3: Subtract

            public void Subtract(BigInteger bi) {
                AssertValid();
                bi.AssertValid();
                Debug.Assert((object)this != (object)bi);

                int idx;
                uint wCarry, uT;

                if (length < bi.length) {
                    goto LNegative;
                }

                wCarry = 1;
                for (idx = 0; idx < bi.length; idx++) {
                    Debug.Assert(0 == wCarry || 1 == wCarry);
                    uT = bi.digits[idx];

                    // NOTE: We should really do:
                    //    wCarry = AddU(ref digits[idx], wCarry);
                    //    wCarry += AddU(ref digits[idx], ~uT);
                    // The only case where this is different than
                    //    wCarry = AddU(ref digits[idx], ~uT + wCarry);
                    // is when 0 == uT and 1 == wCarry, in which case we don't
                    // need to add anything and wCarry should still be 1, so we can
                    // just skip the operations.

                    if (0 != uT || 0 == wCarry) {
                        wCarry = AddU(ref digits[idx], ~uT + wCarry);
                    }
                }
                while (0 == wCarry && idx < length) {
                    wCarry = AddU(ref digits[idx], 0xFFFFFFFF);
                }

                if (0 != wCarry) {
                    if (idx == length) {
                        // Trim off zeros.
                        while (--idx >= 0 && 0 == digits[idx]) {
                        }
                        length = idx + 1;
                    }
                    AssertValid();
                    return;
                }

            LNegative:
                // bi was bigger than this.
                Debug.Assert(false, "Who's subtracting to negative?");
                length = 0;
                AssertValid();
            }
开发者ID:uQr,项目名称:referencesource,代码行数:51,代码来源:XPathConvert.cs

示例4: InitFromBigint

            /*  ----------------------------------------------------------------------------
                InitFromBigint()

                Initialize this big integer from another BigInteger object.
            */
            public void InitFromBigint(BigInteger biSrc) {
                AssertValid();
                biSrc.AssertValid();
                Debug.Assert((object)this != (object)biSrc);

                InitFromRgu(biSrc.digits, biSrc.length);
            }
开发者ID:uQr,项目名称:referencesource,代码行数:12,代码来源:XPathConvert.cs


注:本文中的BigInteger.AssertValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。