本文整理汇总了C#中IntX类的典型用法代码示例。如果您正苦于以下问题:C# IntX类的具体用法?C# IntX怎么用?C# IntX使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntX类属于命名空间,在下文中一共展示了IntX类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add2BigIntXC3
public void Add2BigIntXC3()
{
IntX int1 = new IntX(new uint[] { uint.MaxValue, uint.MaxValue }, false);
IntX int2 = new IntX(new uint[] { 1, 1 }, false);
IntX int3 = new IntX(new uint[] { 0, 1, 1 }, false);
Assert.IsTrue(int1 + int2 == int3);
}
示例2: Simple
public void Simple()
{
IntX int1 = new IntX(8);
int1 *= int1;
int1.Normalize();
Assert.IsTrue(int1 == 64);
}
示例3: Sub2BigIntXC4
public void Sub2BigIntXC4()
{
IntX int1 = new IntX(new uint[] { uint.MaxValue, uint.MaxValue, 1, 1 }, false);
IntX int2 = new IntX(new uint[] { 1, 1 }, false);
IntX int3 = new IntX(new uint[] { 0, 1, 2, 1 }, false);
Assert.IsTrue(int1 == int3 - int2);
}
示例4: Big
public void Big()
{
IntX int1 = new IntX(new uint[] {0, 0, 0x80000000U, 0x7fffffffU}, false);
IntX int2 = new IntX(new uint[] {1, 0, 0x80000000U}, false);
IntX intM = new IntX(new uint[] {2, 0xffffffffU, 0x7fffffffU}, false);
Assert.IsTrue(int1 % int2 == intM);
}
示例5: Add2BigIntX
public void Add2BigIntX()
{
IntX int1 = new IntX(new uint[] { 1, 2, 3 }, false);
IntX int2 = new IntX(new uint[] { 3, 4, 5 }, false);
IntX int3 = new IntX(new uint[] { 4, 6, 8 }, false);
Assert.IsTrue(int1 + int2 == int3);
}
示例6: Big
public void Big()
{
IntX int1 = new IntX(new uint[] { 1, 1 }, false);
IntX int2 = new IntX(new uint[] { 1, 1 }, false);
IntX intRes = new IntX(new uint[] { 1, 2, 1 }, false);
Assert.AreEqual(int1 * int2, intRes);
}
示例7: Multiply
/// <summary>
/// Multiplies two big integers.
/// </summary>
/// <param name="int1">First big integer.</param>
/// <param name="int2">Second big integer.</param>
/// <returns>Resulting big integer.</returns>
/// <exception cref="ArgumentNullException"><paramref name="int1" /> or <paramref name="int2" /> is a null reference.</exception>
/// <exception cref="ArgumentException"><paramref name="int1" /> or <paramref name="int2" /> is too big for multiply operation.</exception>
public virtual IntX Multiply(IntX int1, IntX int2)
{
// Exceptions
if (ReferenceEquals(int1, null))
{
throw new ArgumentNullException("int1", Strings.CantBeNull);
}
else if (ReferenceEquals(int2, null))
{
throw new ArgumentNullException("int2", Strings.CantBeNull);
}
// Special behavior for zero cases
if (int1._length == 0 || int2._length == 0) return new IntX();
// Get new big integer length and check it
ulong newLength = (ulong)int1._length + int2._length;
if (newLength >> 32 != 0)
{
throw new ArgumentException(Strings.IntegerTooBig);
}
// Create resulting big int
IntX newInt = new IntX((uint)newLength, int1._negative ^ int2._negative);
// Perform actual digits multiplication
newInt._length = Multiply(int1._digits, int1._length, int2._digits, int2._length, newInt._digits);
// Normalization may be needed
newInt.TryNormalize();
return newInt;
}
示例8: gcd
//Old GCD algorithm.
public static IntX gcd(IntX a, IntX b) {
if(b == 0) {
return a;
}else {
return gcd(b, a % b);
}
}
示例9: Big3
public void Big3()
{
IntX int1 = new IntX(new uint[] { uint.MaxValue, uint.MaxValue }, false);
IntX int2 = new IntX(new uint[] { uint.MaxValue, uint.MaxValue }, false);
IntX intRes = new IntX(new uint[] { 1, 0, uint.MaxValue - 1, uint.MaxValue }, false);
Assert.IsTrue(int1 * int2 == intRes);
}
示例10: Sub2BigIntX
public void Sub2BigIntX()
{
IntX int1 = new IntX(new uint[] { 1, 2, 3 }, false);
IntX int2 = new IntX(new uint[] { 3, 4, 5 }, false);
IntX int3 = new IntX(new uint[] { 2, 2, 2 }, true);
Assert.IsTrue(int1 - int2 == int3);
}
示例11: Add0IntXNeg
public void Add0IntXNeg()
{
IntX int1 = new IntX(-3);
Assert.IsTrue(int1 + 0 == -3);
Assert.IsTrue(int1 + new IntX() == -3);
Assert.IsTrue(new IntX(0) + new IntX(-1) == -1);
}
示例12: ShouldBeFalseForZero
public void ShouldBeFalseForZero()
{
IntX value = new IntX();
bool result = value.IsOdd;
Assert.That(result, Is.False);
}
示例13: genN
//Generates p, q, and n. Returns an array of p, q, and n in that order.
public static IntX[] genN() {
IntX[] output = new IntX[3];
output[0] = genRandPrime();
output[1] = genRandPrime();
output[2] = output[0] * output[1];
return output;
}
示例14: Performance
public void Performance()
{
IntX intX = new IntX(new uint[] { 0, 1 }, false);
IntX intX2 = intX;
for (int i = 0; i < 1000; ++i) {
intX2 *= intX;
}
}
示例15: Big2
public void Big2()
{
IntX int1 = new IntX(new uint[] { 1, 1 }, false);
IntX int2 = new IntX(new uint[] { 2 }, false);
IntX intRes = new IntX(new uint[] { 2, 2 }, false);
Assert.AreEqual(intRes, int1 * int2);
Assert.AreEqual(intRes, int2 * int1);
}