本文整理汇总了C#中Lidgren.Network.NetBigInteger.Abs方法的典型用法代码示例。如果您正苦于以下问题:C# NetBigInteger.Abs方法的具体用法?C# NetBigInteger.Abs怎么用?C# NetBigInteger.Abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBigInteger
的用法示例。
在下文中一共展示了NetBigInteger.Abs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Gcd
public NetBigInteger Gcd(
NetBigInteger value)
{
if (value.m_sign == 0)
return Abs();
if (m_sign == 0)
return value.Abs();
NetBigInteger r;
NetBigInteger u = this;
NetBigInteger v = value;
while (v.m_sign != 0)
{
r = u.Mod(v);
u = v;
v = r;
}
return u;
}
示例2: DivideAndRemainder
public NetBigInteger[] DivideAndRemainder(
NetBigInteger val)
{
if (val.m_sign == 0)
throw new ArithmeticException("Division by zero error");
NetBigInteger[] biggies = new NetBigInteger[2];
if (m_sign == 0)
{
biggies[0] = Zero;
biggies[1] = Zero;
}
else if (val.QuickPow2Check()) // val is power of two
{
int e = val.Abs().BitLength - 1;
NetBigInteger quotient = Abs().ShiftRight(e);
int[] remainder = LastNBits(e);
biggies[0] = val.m_sign == m_sign ? quotient : quotient.Negate();
biggies[1] = new NetBigInteger(m_sign, remainder, true);
}
else
{
int[] remainder = (int[])m_magnitude.Clone();
int[] quotient = Divide(remainder, val.m_magnitude);
biggies[0] = new NetBigInteger(m_sign * val.m_sign, quotient, true);
biggies[1] = new NetBigInteger(m_sign, remainder, true);
}
return biggies;
}
示例3: Remainder
public NetBigInteger Remainder(
NetBigInteger n)
{
if (n.m_sign == 0)
throw new ArithmeticException("Division by zero error");
if (m_sign == 0)
return Zero;
// For small values, use fast remainder method
if (n.m_magnitude.Length == 1)
{
int val = n.m_magnitude[0];
if (val > 0)
{
if (val == 1)
return Zero;
int rem = Remainder(val);
return rem == 0
? Zero
: new NetBigInteger(m_sign, new int[] { rem }, false);
}
}
if (CompareNoLeadingZeroes(0, m_magnitude, 0, n.m_magnitude) < 0)
return this;
int[] result;
if (n.QuickPow2Check()) // n is power of two
{
result = LastNBits(n.Abs().BitLength - 1);
}
else
{
result = (int[])m_magnitude.Clone();
result = Remainder(result, n.m_magnitude);
}
return new NetBigInteger(m_sign, result, true);
}
示例4: Divide
public NetBigInteger Divide(
NetBigInteger val)
{
if (val.m_sign == 0)
throw new ArithmeticException("Division by zero error");
if (m_sign == 0)
return Zero;
if (val.QuickPow2Check()) // val is power of two
{
NetBigInteger result = Abs().ShiftRight(val.Abs().BitLength - 1);
return val.m_sign == m_sign ? result : result.Negate();
}
int[] mag = (int[])m_magnitude.Clone();
return new NetBigInteger(m_sign * val.m_sign, Divide(mag, val.m_magnitude), true);
}
示例5: Multiply
public NetBigInteger Multiply(
NetBigInteger val)
{
if (m_sign == 0 || val.m_sign == 0)
return Zero;
if (val.QuickPow2Check()) // val is power of two
{
NetBigInteger result = ShiftLeft(val.Abs().BitLength - 1);
return val.m_sign > 0 ? result : result.Negate();
}
if (QuickPow2Check()) // this is power of two
{
NetBigInteger result = val.ShiftLeft(Abs().BitLength - 1);
return m_sign > 0 ? result : result.Negate();
}
int maxBitLength = BitLength + val.BitLength;
int resLength = (maxBitLength + BitsPerInt - 1) / BitsPerInt;
int[] res = new int[resLength];
if (val == this)
{
Square(res, m_magnitude);
}
else
{
Multiply(res, m_magnitude, val.m_magnitude);
}
return new NetBigInteger(m_sign * val.m_sign, res, true);
}