本文整理汇总了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());
}
示例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;
}
示例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();
}