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


C# BigInteger.ToInt32方法代码示例

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


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

示例1: PowRound

 public static BigDecimal PowRound(BigDecimal x, BigInteger n)
 {
     /** For now, the implementation forwards to the cases where n
         * is in the range of the standard integers. This might, however, be
         * implemented to decompose larger powers into cascaded calls to smaller ones.
         */
     if (n.CompareTo(Rational.MaxInt32) > 0 ||
         n.CompareTo(Rational.MinInt32) < 0)
         throw new NotSupportedException("Big power for " + n + " not supported");
     return PowRound(x, n.ToInt32());
 }
开发者ID:tupunco,项目名称:deveel-math,代码行数:11,代码来源:BigMath.cs

示例2: Jacobi

        /// <summary>
        /// Computes the value of the Jacobi symbol (A|B). 
        /// </summary>
        /// 
        /// <param name="A">The integer value</param>
        /// <param name="B">The integer value</param>
        /// 
        /// <returns>Returns value of the jacobi symbol (A|B)</returns>
        public static int Jacobi(BigInteger A, BigInteger B)
        {
            BigInteger a, b, v;
            long k = 1;

            // test trivial cases
            if (B.Equals(ZERO))
            {
                a = A.Abs();
                return a.Equals(ONE) ? 1 : 0;
            }

            if (!A.TestBit(0) && !B.TestBit(0))
                return 0;

            a = A;
            b = B;

            if (b.Signum() == -1)
            { // b < 0
                b = b.Negate();
                if (a.Signum() == -1)
                    k = -1;
            }

            v = ZERO;
            while (!b.TestBit(0))
            {
                v = v.Add(ONE);
                b = b.Divide(TWO);
            }

            if (v.TestBit(0))
                k = k * _jacobiTable[a.ToInt32() & 7];

            if (a.Signum() < 0)
            {
                if (b.TestBit(1))
                    k = -k;
                a = a.Negate();
            }

            // main loop
            while (a.Signum() != 0)
            {
                v = ZERO;
                while (!a.TestBit(0))
                { // a is even
                    v = v.Add(ONE);
                    a = a.Divide(TWO);
                }
                if (v.TestBit(0))
                    k = k * _jacobiTable[b.ToInt32() & 7];

                if (a.CompareTo(b) < 0)
                {
                    // swap and correct intermediate result
                    BigInteger x = a;
                    a = b;
                    b = x;
                    if (a.TestBit(1) && b.TestBit(1))
                        k = -k;
                }
                a = a.Subtract(b);
            }

            return b.Equals(ONE) ? (int)k : 0;
        }
开发者ID:Steppenwolfe65,项目名称:Rainbow-NET,代码行数:76,代码来源:BigMath.cs

示例3: Next

        /// <summary>
        /// Get a pseudo random 32bit integer
        /// </summary>
        /// 
        /// <returns>Random Int32</returns>
        public Int32 Next()
        {
            // Xi+1 = (X pow 2) mod N
            _X = _X.Multiply(_X).Mod(_N);

            return _X.ToInt32();
        }
开发者ID:modulexcite,项目名称:CEX,代码行数:12,代码来源:BBSG.cs


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