예제 #1
0
        private BigInteger DoUnaryOperatorSN(BigInteger num1, string op)
        {
            switch (op)
            {
            case "uSign":
                return(new BigInteger(num1.Sign));

            case "u~":
                return(~(num1));

            case "uLog10":
                return(MyBigIntImp.ApproximateBigInteger(BigInteger.Log10(num1)));

            case "uLog":
                return(MyBigIntImp.ApproximateBigInteger(BigInteger.Log(num1)));

            case "uAbs":
                return(BigInteger.Abs(num1));

            case "uNegate":
                return(BigInteger.Negate(num1));

            case "u--":
                return(--(num1));

            case "u++":
                return(++(num1));

            case "u-":
                return(-(num1));

            case "u+":
                return(+(num1));

            case "uMultiply":
                return(BigInteger.Multiply(num1, num1));

            case "u*":
                return(num1 * num1);

            default:
                throw new ArgumentException(String.Format("Invalid operation found: {0}", op));
            }
        }
예제 #2
0
        public static void RunZeroTests_NET40()
#endif
        {
            BigInteger bigInteger;

            byte[] tempByteArray;

            // BigInteger.Zero == 0
            Assert.AreEqual("0", BigInteger.Zero.ToString());
            Assert.AreEqual(new BigInteger((Int64)(0)), BigInteger.Zero);
            Assert.AreEqual(new BigInteger((Double)(0)), BigInteger.Zero);
            Assert.AreEqual(new BigInteger(new byte[] { 0, 0, 0, 0 }), BigInteger.Zero);
            Assert.AreEqual(BigInteger.One + BigInteger.MinusOne, BigInteger.Zero);
            Assert.AreEqual(BigInteger.One - BigInteger.One, BigInteger.Zero);
            Assert.AreEqual(BigInteger.MinusOne - BigInteger.MinusOne, BigInteger.Zero);

            // Identities with BigInteger.Zero
            for (int i = 0; i < s_samples; i++)
            {
                tempByteArray = GetRandomByteArray(s_random);
                bigInteger    = new BigInteger(tempByteArray);

                Assert.AreEqual(BigInteger.Zero, BigInteger.Zero * bigInteger);
                Assert.AreEqual(bigInteger, bigInteger - BigInteger.Zero);
                Assert.AreEqual(BigInteger.MinusOne * bigInteger, BigInteger.Zero - bigInteger);
                Assert.AreEqual(bigInteger, bigInteger + BigInteger.Zero);
                Assert.AreEqual(bigInteger, BigInteger.Zero + bigInteger);

                Assert.Throws <DivideByZeroException>(() =>
                {
                    BigInteger tempBigInteger = bigInteger / BigInteger.Zero;
                });

                if (!MyBigIntImp.IsZero(tempByteArray))
                {
                    Assert.AreEqual(BigInteger.Zero, BigInteger.Zero / bigInteger);
                }
            }
        }
예제 #3
0
 private static string Print(byte[] bytes)
 {
     return(MyBigIntImp.Print(bytes));
 }
예제 #4
0
 private static byte[] GetRandomByteArray(Random random, int size)
 {
     return(MyBigIntImp.GetRandomByteArray(random, size));
 }
예제 #5
0
 private static Byte[] GetRandomByteArray(Random random)
 {
     return(MyBigIntImp.GetRandomByteArray(random, random.Next(0, 1024)));
 }
예제 #6
0
        public static void RunAbsoluteValueTests()
        {
            byte[] byteArray = new byte[0];

            // AbsoluteValue Method - Large BigIntegers
            for (int i = 0; i < s_samples; i++)
            {
                byteArray = GetRandomByteArray(s_random);
                VerifyAbsoluteValueString(Print(byteArray) + "uAbs");
            }

            // AbsoluteValue Method - Small BigIntegers
            for (int i = 0; i < s_samples; i++)
            {
                byteArray = MyBigIntImp.GetRandomByteArray(s_random, 2);
                VerifyAbsoluteValueString(Print(byteArray) + "uAbs");
            }

            // AbsoluteValue Method - zero
            VerifyAbsoluteValueString("0 uAbs");

            // AbsoluteValue Method - -1
            VerifyAbsoluteValueString("-1 uAbs");

            // AbsoluteValue Method - 1
            VerifyAbsoluteValueString("1 uAbs");

            // AbsoluteValue Method - Int32.MinValue
            VerifyAbsoluteValueString(Int32.MinValue.ToString() + " uAbs");

            // AbsoluteValue Method - Int32.MinValue-1
            VerifyAbsoluteValueString(Int32.MinValue.ToString() + " -1 b+ uAbs");

            // AbsoluteValue Method - Int32.MinValue+1
            VerifyAbsoluteValueString(Int32.MinValue.ToString() + " 1 b+ uAbs");

            // AbsoluteValue Method - Int32.MaxValue
            VerifyAbsoluteValueString(Int32.MaxValue.ToString() + " uAbs");

            // AbsoluteValue Method - Int32.MaxValue-1
            VerifyAbsoluteValueString(Int32.MaxValue.ToString() + " -1 b+ uAbs");

            // AbsoluteValue Method - Int32.MaxValue+1
            VerifyAbsoluteValueString(Int32.MaxValue.ToString() + " 1 b+ uAbs");

            // AbsoluteValue Method - Int64.MinValue
            VerifyAbsoluteValueString(Int64.MinValue.ToString() + " uAbs");

            // AbsoluteValue Method - Int64.MinValue-1
            VerifyAbsoluteValueString(Int64.MinValue.ToString() + " -1 b+ uAbs");

            // AbsoluteValue Method - Int64.MinValue+1
            VerifyAbsoluteValueString(Int64.MinValue.ToString() + " 1 b+ uAbs");

            // AbsoluteValue Method - Int64.MaxValue
            VerifyAbsoluteValueString(Int64.MaxValue.ToString() + " uAbs");

            // AbsoluteValue Method - Int64.MaxValue-1
            VerifyAbsoluteValueString(Int64.MaxValue.ToString() + " -1 b+ uAbs");

            // AbsoluteValue Method - Int64.MaxValue+1
            VerifyAbsoluteValueString(Int64.MaxValue.ToString() + " 1 b+ uAbs");
        }
예제 #7
0
        private static void RunPositiveTests(Random random)
        {
            BigInteger bigInteger1, bigInteger2;
            int        expectedResult;

            byte[] byteArray;
            bool   isNegative;

            //1 Inputs from BigInteger Properties
            // BigInteger.MinusOne, BigInteger.MinusOne
            VerifyComparison(BigInteger.MinusOne, BigInteger.MinusOne, 0);

            // BigInteger.MinusOne, BigInteger.Zero
            VerifyComparison(BigInteger.MinusOne, BigInteger.Zero, -1);

            // BigInteger.MinusOne, BigInteger.One
            VerifyComparison(BigInteger.MinusOne, BigInteger.One, -1);

            // BigInteger.MinusOne, Large Negative
            VerifyComparison(BigInteger.MinusOne, -1L * ((BigInteger)Int64.MaxValue), 1);

            // BigInteger.MinusOne, Small Negative
            VerifyComparison(BigInteger.MinusOne, -1L * ((BigInteger)Int16.MaxValue), 1);

            // BigInteger.MinusOne, Large Number
            VerifyComparison(BigInteger.MinusOne, (BigInteger)Int32.MaxValue + 1, -1);

            // BigInteger.MinusOne, Small Number
            VerifyComparison(BigInteger.MinusOne, (BigInteger)Int32.MaxValue - 1, -1);

            // BigInteger.MinusOne, One Less
            VerifyComparison(BigInteger.MinusOne, BigInteger.MinusOne - 1, 1);


            // BigInteger.Zero, BigInteger.Zero
            VerifyComparison(BigInteger.Zero, BigInteger.Zero, 0);

            // BigInteger.Zero, Large Negative
            VerifyComparison(BigInteger.Zero, -1L * ((BigInteger)Int32.MaxValue + 1), 1);

            // BigInteger.Zero, Small Negative
            VerifyComparison(BigInteger.Zero, -1L * ((BigInteger)Int32.MaxValue - 1), 1);

            // BigInteger.Zero, Large Number
            VerifyComparison(BigInteger.Zero, (BigInteger)Int32.MaxValue + 1, -1);

            // BigInteger.Zero, Small Number
            VerifyComparison(BigInteger.Zero, (BigInteger)Int32.MaxValue - 1, -1);


            // BigInteger.One, BigInteger.One
            VerifyComparison(BigInteger.One, BigInteger.One, 0);

            // BigInteger.One, BigInteger.MinusOne
            VerifyComparison(BigInteger.One, BigInteger.MinusOne, 1);

            // BigInteger.One, BigInteger.Zero
            VerifyComparison(BigInteger.One, BigInteger.Zero, 1);

            // BigInteger.One, Large Negative
            VerifyComparison(BigInteger.One, -1 * ((BigInteger)Int32.MaxValue + 1), 1);

            // BigInteger.One, Small Negative
            VerifyComparison(BigInteger.One, -1 * ((BigInteger)Int32.MaxValue - 1), 1);

            // BigInteger.One, Large Number
            VerifyComparison(BigInteger.One, (BigInteger)Int32.MaxValue + 1, -1);

            // BigInteger.One, Small Number
            VerifyComparison(BigInteger.One, (BigInteger)Int32.MaxValue - 1, -1);

            //Basic Checks
            // BigInteger.MinusOne, (Int32) -1
            VerifyComparison(BigInteger.MinusOne, (Int32)(-1), 0);

            // BigInteger.Zero, (Int32) 0
            VerifyComparison(BigInteger.Zero, (Int32)(0), 0);

            // BigInteger.One, 1
            VerifyComparison(BigInteger.One, (Int32)(1), 0);


            //1 Inputs Around the boundary of UInt32
            // -1 * UInt32.MaxValue, -1 * UInt32.MaxValue
            VerifyComparison(-1L * (BigInteger)UInt32.MaxValue - 1, -1L * (BigInteger)UInt32.MaxValue - 1, 0);

            // -1 * UInt32.MaxValue, -1 * UInt32.MaxValue -1
            VerifyComparison(-1L * (BigInteger)UInt32.MaxValue, (-1L * (BigInteger)UInt32.MaxValue) - 1L, 1);

            // UInt32.MaxValue, -1 * UInt32.MaxValue
            VerifyComparison((BigInteger)UInt32.MaxValue, -1L * (BigInteger)UInt32.MaxValue, 1);

            // UInt32.MaxValue, UInt32.MaxValue
            VerifyComparison((BigInteger)UInt32.MaxValue, (BigInteger)UInt32.MaxValue, 0);

            // UInt32.MaxValue, UInt32.MaxValue + 1
            VerifyComparison((BigInteger)UInt32.MaxValue, (BigInteger)UInt32.MaxValue + 1, -1);

            // UInt64.MaxValue, UInt64.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue, (BigInteger)UInt64.MaxValue, 0);

            // UInt64.MaxValue + 1, UInt64.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue + 1, UInt64.MaxValue, 1);

            //Other cases
            // -1 * Large Bigint, -1 * Large BigInt
            VerifyComparison(-1L * ((BigInteger)Int32.MaxValue + 1), -1L * ((BigInteger)Int32.MaxValue + 1), 0);

            // Large Bigint, Large Negative BigInt
            VerifyComparison((BigInteger)Int32.MaxValue + 1, -1L * ((BigInteger)Int32.MaxValue + 1), 1);

            // Large Bigint, UInt32.MaxValue
            VerifyComparison((BigInteger)Int64.MaxValue + 1, (BigInteger)UInt32.MaxValue, 1);

            // Large Bigint, One More
            VerifyComparison((BigInteger)Int32.MaxValue + 1, ((BigInteger)Int32.MaxValue) + 2, -1);

            // -1 * Small Bigint, -1 * Small BigInt
            VerifyComparison(-1L * ((BigInteger)Int32.MaxValue - 1), -1L * ((BigInteger)Int32.MaxValue - 1), 0);

            // Small Bigint, Small Negative BigInt
            VerifyComparison((BigInteger)Int32.MaxValue - 1, -1L * ((BigInteger)Int32.MaxValue - 1), 1);

            // Small Bigint, UInt32.MaxValue
            VerifyComparison((BigInteger)Int32.MaxValue - 1, (BigInteger)UInt32.MaxValue - 1, -1);

            // Small Bigint, One More
            VerifyComparison((BigInteger)Int32.MaxValue - 2, ((BigInteger)Int32.MaxValue) - 1, -1);

            //BigInteger vs. Int32

            // One Larger (BigInteger), Int32.MaxValue
            VerifyComparison((BigInteger)Int32.MaxValue + 1, Int32.MaxValue, 1);

            // Larger BigInteger, Int32.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue + 1, Int32.MaxValue, 1);

            // Smaller BigInteger, Int32.MaxValue
            VerifyComparison((BigInteger)Int16.MinValue - 1, Int32.MaxValue, -1);

            // One Smaller (BigInteger), Int32.MaxValue
            VerifyComparison((BigInteger)Int32.MaxValue - 1, Int32.MaxValue, -1);

            // (BigInteger) Int32.MaxValue, Int32.MaxValue
            VerifyComparison((BigInteger)Int32.MaxValue, Int32.MaxValue, 0);

            //BigInteger vs. UInt32
            // One Larger (BigInteger), UInt32.MaxValue
            VerifyComparison((BigInteger)UInt32.MaxValue + 1, UInt32.MaxValue, 1);

            // Larger BigInteger, UInt32.MaxValue
            VerifyComparison((BigInteger)Int64.MaxValue + 1, UInt32.MaxValue, 1);

            // Smaller BigInteger, UInt32.MaxValue
            VerifyComparison((BigInteger)Int16.MinValue - 1, UInt32.MaxValue, -1);

            // One Smaller (BigInteger), UInt32.MaxValue
            VerifyComparison((BigInteger)UInt32.MaxValue - 1, UInt32.MaxValue, -1);

            // (BigInteger UInt32.MaxValue, UInt32.MaxValue
            VerifyComparison((BigInteger)UInt32.MaxValue, UInt32.MaxValue, 0);


            //BigInteger vs. UInt64
            // One Larger (BigInteger), UInt64.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue + 1, UInt64.MaxValue, 1);

            // Larger BigInteger, UInt64.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue + 100, UInt64.MaxValue, 1);

            // Smaller BigInteger, UInt64.MaxValue
            VerifyComparison((BigInteger)Int16.MinValue - 1, UInt64.MaxValue, -1);

            // One Smaller (BigInteger), UInt64.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue - 1, UInt64.MaxValue, -1);

            // (BigInteger UInt64.MaxValue, UInt64.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue, UInt64.MaxValue, 0);

            //BigInteger vs. Int64
            // One Smaller (BigInteger), Int64.MaxValue
            VerifyComparison((BigInteger)Int64.MaxValue - 1, Int64.MaxValue, -1);

            // Larger BigInteger, Int64.MaxValue
            VerifyComparison((BigInteger)UInt64.MaxValue + 100, Int64.MaxValue, 1);

            // Smaller BigInteger, Int32.MaxValue
            VerifyComparison((BigInteger)Int16.MinValue - 1, Int64.MaxValue, -1);

            // (BigInteger Int64.MaxValue, Int64.MaxValue
            VerifyComparison((BigInteger)Int64.MaxValue, Int64.MaxValue, 0);

            // One Larger (BigInteger), Int64.MaxValue
            VerifyComparison((BigInteger)Int64.MaxValue + 1, Int64.MaxValue, 1);


            //1 Random Inputs
            // Random BigInteger only differs by sign

            for (int i = 0; i < NumberOfRandomIterations; ++i)
            {
                do
                {
                    byteArray = GetRandomByteArray(random);
                }while (MyBigIntImp.IsZero(byteArray));

                BigInteger b2 = new BigInteger(byteArray);
                if (b2 > (BigInteger)0)
                {
                    VerifyComparison(b2, -1L * b2, 1);
                }
                else
                {
                    VerifyComparison(b2, -1L * b2, -1);
                }
            }

            // Random BigInteger, Random BigInteger
            for (int i = 0; i < NumberOfRandomIterations; ++i)
            {
                expectedResult = GetRandomInputForComparison(random, out bigInteger1, out bigInteger2);
                VerifyComparison(bigInteger1, bigInteger2, expectedResult);
            }

            // Random BigInteger
            for (int i = 0; i < NumberOfRandomIterations; ++i)
            {
                byteArray  = GetRandomByteArray(random);
                isNegative = 0 == random.Next(0, 2);
                VerifyComparison(new BigInteger(byteArray), isNegative, new BigInteger(byteArray), isNegative, 0);
            }

            //1 Identical values constructed multiple ways
            // BigInteger.Zero, BigInteger constructed with a byte[] isNegative=true
            VerifyComparison(BigInteger.Zero, false, new BigInteger(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }), true, 0);

            // BigInteger.Zero, BigInteger constructed with a byte[] isNegative=false
            VerifyComparison(BigInteger.Zero, false, new BigInteger(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }), false, 0);

            // BigInteger.Zero, BigInteger constructed from an Int64
            VerifyComparison(BigInteger.Zero, 0L, 0);

            // BigInteger.Zero, BigInteger constructed from a Double
            VerifyComparison(BigInteger.Zero, (BigInteger)0d, 0);

            // BigInteger.Zero, BigInteger constructed from a Decimal
            VerifyComparison(BigInteger.Zero, (BigInteger)0, 0);

            // BigInteger.Zero, BigInteger constructed with Addition
            byteArray  = GetRandomByteArray(random);
            isNegative = 0 == random.Next(0, 2);
            VerifyComparison(BigInteger.Zero, false, new BigInteger(byteArray) + (-1 * new BigInteger(byteArray)), isNegative, 0);

            // BigInteger.Zero, BigInteger constructed with Subtraction
            byteArray  = GetRandomByteArray(random);
            isNegative = 0 == random.Next(0, 2);
            VerifyComparison(BigInteger.Zero, false, new BigInteger(byteArray) - new BigInteger(byteArray), isNegative, 0);

            // BigInteger.Zero, BigInteger constructed with Multiplication
            byteArray  = GetRandomByteArray(random);
            isNegative = 0 == random.Next(0, 2);
            VerifyComparison(BigInteger.Zero, false, 0 * new BigInteger(byteArray), isNegative, 0);

            // BigInteger.Zero, BigInteger constructed with Division
            do
            {
                byteArray = GetRandomByteArray(random);
            }while (MyBigIntImp.IsZero(byteArray));

            isNegative = 0 == random.Next(0, 2);
            VerifyComparison(BigInteger.Zero, false, 0 / new BigInteger(byteArray), isNegative, 0);

            // BigInteger.One, BigInteger constructed with a byte[]
            VerifyComparison(BigInteger.One, false, new BigInteger(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 }), false, 0);

            // BigInteger.One, BigInteger constructed from an Int64
            VerifyComparison(BigInteger.One, 1L, 0);

            // BigInteger.One, BigInteger constructed from a Double
            VerifyComparison(BigInteger.One, (BigInteger)1d, 0);

            // BigInteger.One, BigInteger constructed from a Decimal
            VerifyComparison(BigInteger.One, (BigInteger)1, 0);

            // BigInteger.One, BigInteger constructed with Addition
            byteArray  = GetRandomByteArray(random);
            isNegative = 0 == random.Next(0, 2);
            VerifyComparison(BigInteger.One, false, (((BigInteger)(-1)) * new BigInteger(byteArray)) + (new BigInteger(byteArray)) + 1, false, 0);

            // BigInteger.One, BigInteger constructed with Subtraction
            byteArray  = GetRandomByteArray(random);
            isNegative = 0 == random.Next(0, 2);
            BigInteger b = new BigInteger(byteArray);

            if (b > (BigInteger)0)
            {
                VerifyComparison(BigInteger.One, false, (b + 1) - (b), false, 0);
            }
            else
            {
                b = -1L * b;
                VerifyComparison(BigInteger.One, false, (b + 1) - (b), false, 0);
                b = -1L * b;
            }

            // BigInteger.One, BigInteger constructed with Multiplication
            byteArray  = GetRandomByteArray(random);
            isNegative = 0 == random.Next(0, 2);
            VerifyComparison(BigInteger.One, (BigInteger)1 * (BigInteger)1, 0);

            // BigInteger.One, BigInteger constructed with Division
            do
            {
                byteArray = GetRandomByteArray(random);
            }while (MyBigIntImp.IsZero(byteArray));

            BigInteger b1 = new BigInteger(byteArray);

            VerifyComparison(BigInteger.One, false, b1 / b1, false, 0);
        }
예제 #8
0
        private static void VerifyCtorByteArray(byte[] value)
        {
            BigInteger bigInteger;

            byte[] roundTrippedByteArray;
            bool   isZero = MyBigIntImp.IsZero(value);

            bigInteger = new BigInteger(value);
            VerifyCtorByteSpan(value);

            roundTrippedByteArray = bigInteger.ToByteArray();

            for (int i = Math.Min(value.Length, roundTrippedByteArray.Length) - 1; 0 <= i; --i)
            {
                Assert.True(value[i] == roundTrippedByteArray[i], String.Format("Round Tripped ByteArray at {0}", i));
            }
            if (value.Length < roundTrippedByteArray.Length)
            {
                for (int i = value.Length; i < roundTrippedByteArray.Length; ++i)
                {
                    Assert.True(0 == roundTrippedByteArray[i],
                                String.Format("Round Tripped ByteArray is larger than the original array and byte is non zero at {0}", i));
                }
            }
            else if (value.Length > roundTrippedByteArray.Length)
            {
                for (int i = roundTrippedByteArray.Length; i < value.Length; ++i)
                {
                    Assert.False((((0 != value[i]) && ((roundTrippedByteArray[roundTrippedByteArray.Length - 1] & 0x80) == 0)) ||
                                  ((0xFF != value[i]) && ((roundTrippedByteArray[roundTrippedByteArray.Length - 1] & 0x80) != 0))),
                                 String.Format("Round Tripped ByteArray is smaller than the original array and byte is non zero at {0}", i));
                }
            }

            if (value.Length < 8)
            {
                byte[] newvalue = new byte[8];

                for (int i = 0; i < 8; i++)
                {
                    if (bigInteger < 0)
                    {
                        newvalue[i] = 0xFF;
                    }
                    else
                    {
                        newvalue[i] = 0;
                    }
                }

                for (int i = 0; i < value.Length; i++)
                {
                    newvalue[i] = value[i];
                }

                value = newvalue;
            }
            else if (value.Length > 8)
            {
                int newlength = value.Length;

                for (; newlength > 8; newlength--)
                {
                    if (bigInteger < 0)
                    {
                        if ((value[newlength - 1] != 0xFF) | ((value[newlength - 2] & 0x80) == 0))
                        {
                            break;
                        }
                    }
                    else
                    {
                        if ((value[newlength - 1] != 0) | ((value[newlength - 2] & 0x80) != 0))
                        {
                            break;
                        }
                    }
                }

                byte[] newvalue = new byte[newlength];

                for (int i = 0; i < newlength; i++)
                {
                    newvalue[i] = value[i];
                }

                value = newvalue;
            }

            if (IsOutOfRangeInt64(value))
            {
                // Try subtracting a value from the BigInteger that will allow it to be represented as an Int64
                byte[]     tempByteArray;
                BigInteger tempBigInteger;
                bool       isNeg = ((value[value.Length - 1] & 0x80) != 0);

                tempByteArray = new byte[value.Length];
                Array.Copy(value, 8, tempByteArray, 8, value.Length - 8);

                tempBigInteger = bigInteger - (new BigInteger(tempByteArray));

                tempByteArray = new byte[8];
                Array.Copy(value, 0, tempByteArray, 0, 8);

                if (!(((tempByteArray[7] & 0x80) == 0) ^ isNeg))
                {
                    tempByteArray[7] ^= 0x80;
                    tempBigInteger    = tempBigInteger + (new BigInteger(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0x80 }));
                }
                if (isNeg & (tempBigInteger > 0))
                {
                    tempBigInteger = tempBigInteger + (new BigInteger(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0xFF }));
                }

                Assert.Equal(BitConverter.ToInt64(tempByteArray, 0), (Int64)tempBigInteger);
            }
            else
            {
                Assert.Equal(BitConverter.ToInt64(value, 0), (Int64)bigInteger);
            }

            if (IsOutOfRangeUInt64(value))
            {
                // Try subtracting a value from the BigInteger that will allow it to be represented as an UInt64
                byte[]     tempByteArray;
                BigInteger tempBigInteger;
                bool       isNeg = ((value[value.Length - 1] & 0x80) != 0);

                tempByteArray = new byte[value.Length];
                Array.Copy(value, 8, tempByteArray, 8, value.Length - 8);

                tempBigInteger = bigInteger - (new BigInteger(tempByteArray));

                tempByteArray = new byte[8];
                Array.Copy(value, 0, tempByteArray, 0, 8);

                if ((tempByteArray[7] & 0x80) != 0)
                {
                    tempByteArray[7] &= 0x7f;
                    if (tempBigInteger < 0)
                    {
                        tempBigInteger = tempBigInteger - (new BigInteger(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0x80 }));
                    }
                    else
                    {
                        tempBigInteger = tempBigInteger + (new BigInteger(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0x80 }));
                    }
                }

                Assert.Equal(BitConverter.ToUInt64(tempByteArray, 0), (UInt64)tempBigInteger);
            }
            else
            {
                Assert.Equal(BitConverter.ToUInt64(value, 0), (UInt64)bigInteger);
            }

            VerifyBigIntegerUsingIdentities(bigInteger, isZero);
        }
예제 #9
0
        public bool DoNextOperation()
        {
            string op          = "";
            bool   ret         = false;
            bool   checkValues = false;

            BigInteger snnum1 = 0;
            BigInteger snnum2 = 0;
            BigInteger snnum3 = 0;
            BigInteger mynum1 = 0;
            BigInteger mynum2 = 0;
            BigInteger mynum3 = 0;

            if (operators.Count == 0)
            {
                return(false);
            }
            op = operators.Dequeue();

            if (op.StartsWith("u"))
            {
                checkValues = true;

                snnum1 = snCalc.Pop();
                snCalc.Push(DoUnaryOperatorSN(snnum1, op));

                mynum1 = myCalc.Pop();
                myCalc.Push(MyBigIntImp.DoUnaryOperatorMine(mynum1, op));

                ret = true;
            }
            else if (op.StartsWith("b"))
            {
                checkValues = true;

                snnum1 = snCalc.Pop();
                snnum2 = snCalc.Pop();
                snCalc.Push(DoBinaryOperatorSN(snnum1, snnum2, op));

                mynum1 = myCalc.Pop();
                mynum2 = myCalc.Pop();
                myCalc.Push(MyBigIntImp.DoBinaryOperatorMine(mynum1, mynum2, op));

                ret = true;
            }
            else if (op.StartsWith("t"))
            {
                checkValues = true;
                snnum1      = snCalc.Pop();
                snnum2      = snCalc.Pop();
                snnum3      = snCalc.Pop();

                snCalc.Push(DoTertanaryOperatorSN(snnum1, snnum2, snnum3, op));

                mynum1 = myCalc.Pop();
                mynum2 = myCalc.Pop();
                mynum3 = myCalc.Pop();
                myCalc.Push(MyBigIntImp.DoTertanaryOperatorMine(mynum1, mynum2, mynum3, op));

                ret = true;
            }
            else
            {
                if (op.Equals("make"))
                {
                    snnum1 = DoConstruction();
                    snCalc.Push(snnum1);
                    myCalc.Push(snnum1);
                }
                else if (op.Equals("Corruption"))
                {
                    snCalc.Push(-33);
                    myCalc.Push(-555);
                }
                else if (BigInteger.TryParse(op, out snnum1))
                {
                    snCalc.Push(snnum1);
                    myCalc.Push(snnum1);
                }
                else
                {
                    Console.WriteLine("Failed to parse string {0}", op);
                }

                ret = true;
            }

            if (checkValues)
            {
                if ((snnum1 != mynum1) || (snnum2 != mynum2) || (snnum3 != mynum3))
                {
                    operators.Enqueue("Corruption");
                }
            }

            return(ret);
        }
예제 #10
0
 private static String Print(byte[] bytes)
 {
     return(MyBigIntImp.PrintFormatX(bytes));
 }
예제 #11
0
        private BigInteger DoBinaryOperatorSN(BigInteger num1, BigInteger num2, string op)
        {
            switch (op)
            {
            case "bMin":
                return(BigInteger.Min(num1, num2));

            case "bMax":
                return(BigInteger.Max(num1, num2));

            case "b>>":
                return(num1 >> (int)num2);

            case "b<<":
                return(num1 << (int)num2);

            case "b^":
                return(num1 ^ num2);

            case "b|":
                return(num1 | num2);

            case "b&":
                return(num1 & num2);

            case "b%":
                return(num1 % num2);

            case "b/":
                return(num1 / num2);

            case "b*":
                return(num1 * num2);

            case "b-":
                return(num1 - num2);

            case "b+":
                return(num1 + num2);

            case "bLog":
                return(MyBigIntImp.ApproximateBigInteger(BigInteger.Log(num1, (double)num2)));

            case "bGCD":
                return(BigInteger.GreatestCommonDivisor(num1, num2));

            case "bPow":
                int arg2 = (int)num2;
                return(BigInteger.Pow(num1, arg2));

            case "bDivRem":
                BigInteger num3;
                BigInteger ret = BigInteger.DivRem(num1, num2, out num3);
                SetSNOutCheck(num3);
                return(ret);

            case "bRemainder":
                return(BigInteger.Remainder(num1, num2));

            case "bDivide":
                return(BigInteger.Divide(num1, num2));

            case "bMultiply":
                return(BigInteger.Multiply(num1, num2));

            case "bSubtract":
                return(BigInteger.Subtract(num1, num2));

            case "bAdd":
                return(BigInteger.Add(num1, num2));

            default:
                throw new ArgumentException(String.Format("Invalid operation found: {0}", op));
            }
        }
예제 #12
0
파일: Driver.cs 프로젝트: yang73137/corefx
 private void Log(BigInteger a, BigInteger b, BigInteger expected)
 {
     Assert.Equal(MyBigIntImp.ApproximateBigInteger(BigInteger.Log(a, (double)b)), expected);
 }
예제 #13
0
파일: Driver.cs 프로젝트: yang73137/corefx
 private void Log10(BigInteger a, BigInteger expected)
 {
     Assert.Equal(MyBigIntImp.ApproximateBigInteger(BigInteger.Log10(a)), expected);
 }
예제 #14
0
파일: Driver.cs 프로젝트: yang73137/corefx
 private static byte[] GetRandomByteArray(Random random)
 {
     return(MyBigIntImp.GetNonZeroRandomByteArray(random, random.Next(1, 18)));
 }
예제 #15
0
파일: Driver.cs 프로젝트: yang73137/corefx
        public static void RunTests()
        {
            int cycles = 1;

            //Get the BigIntegers to be testing;
            b1      = new BigInteger(GetRandomByteArray(s_random));
            b2      = new BigInteger(GetRandomByteArray(s_random));
            b3      = new BigInteger(GetRandomByteArray(s_random));
            results = new BigInteger[32][];
            // ...Sign
            results[0]    = new BigInteger[3];
            results[0][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "uSign");
            results[0][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "uSign");
            results[0][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "uSign");
            // ...Op ~
            results[1]    = new BigInteger[3];
            results[1][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "u~");
            results[1][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "u~");
            results[1][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "u~");
            // ...Log10
            results[2]    = new BigInteger[3];
            results[2][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "uLog10");
            results[2][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "uLog10");
            results[2][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "uLog10");
            // ...Log
            results[3]    = new BigInteger[3];
            results[3][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "uLog");
            results[3][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "uLog");
            results[3][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "uLog");
            // ...Abs
            results[4]    = new BigInteger[3];
            results[4][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "uAbs");
            results[4][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "uAbs");
            results[4][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "uAbs");
            // ...Op --
            results[5]    = new BigInteger[3];
            results[5][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "u--");
            results[5][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "u--");
            results[5][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "u--");
            // ...Op ++
            results[6]    = new BigInteger[3];
            results[6][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "u++");
            results[6][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "u++");
            results[6][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "u++");
            // ...Negate
            results[7]    = new BigInteger[3];
            results[7][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "uNegate");
            results[7][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "uNegate");
            results[7][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "uNegate");
            // ...Op -
            results[8]    = new BigInteger[3];
            results[8][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "u-");
            results[8][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "u-");
            results[8][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "u-");
            // ...Op +
            results[9]    = new BigInteger[3];
            results[9][0] = MyBigIntImp.DoUnaryOperatorMine(b1, "u+");
            results[9][1] = MyBigIntImp.DoUnaryOperatorMine(b2, "u+");
            results[9][2] = MyBigIntImp.DoUnaryOperatorMine(b3, "u+");
            // ...Min
            results[10]    = new BigInteger[9];
            results[10][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bMin");
            results[10][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bMin");
            results[10][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bMin");
            results[10][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bMin");
            results[10][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bMin");
            results[10][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bMin");
            results[10][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bMin");
            results[10][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bMin");
            results[10][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bMin");
            // ...Max
            results[11]    = new BigInteger[9];
            results[11][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bMax");
            results[11][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bMax");
            results[11][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bMax");
            results[11][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bMax");
            results[11][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bMax");
            results[11][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bMax");
            results[11][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bMax");
            results[11][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bMax");
            results[11][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bMax");
            // ...Op >>
            results[12]    = new BigInteger[9];
            results[12][0] = MyBigIntImp.DoBinaryOperatorMine(b1, Makeint(b1), "b>>");
            results[12][1] = MyBigIntImp.DoBinaryOperatorMine(b1, Makeint(b2), "b>>");
            results[12][2] = MyBigIntImp.DoBinaryOperatorMine(b1, Makeint(b3), "b>>");
            results[12][3] = MyBigIntImp.DoBinaryOperatorMine(b2, Makeint(b1), "b>>");
            results[12][4] = MyBigIntImp.DoBinaryOperatorMine(b2, Makeint(b2), "b>>");
            results[12][5] = MyBigIntImp.DoBinaryOperatorMine(b2, Makeint(b3), "b>>");
            results[12][6] = MyBigIntImp.DoBinaryOperatorMine(b3, Makeint(b1), "b>>");
            results[12][7] = MyBigIntImp.DoBinaryOperatorMine(b3, Makeint(b2), "b>>");
            results[12][8] = MyBigIntImp.DoBinaryOperatorMine(b3, Makeint(b3), "b>>");
            // ...Op <<
            results[13]    = new BigInteger[9];
            results[13][0] = MyBigIntImp.DoBinaryOperatorMine(b1, Makeint(b1), "b<<");
            results[13][1] = MyBigIntImp.DoBinaryOperatorMine(b1, Makeint(b2), "b<<");
            results[13][2] = MyBigIntImp.DoBinaryOperatorMine(b1, Makeint(b3), "b<<");
            results[13][3] = MyBigIntImp.DoBinaryOperatorMine(b2, Makeint(b1), "b<<");
            results[13][4] = MyBigIntImp.DoBinaryOperatorMine(b2, Makeint(b2), "b<<");
            results[13][5] = MyBigIntImp.DoBinaryOperatorMine(b2, Makeint(b3), "b<<");
            results[13][6] = MyBigIntImp.DoBinaryOperatorMine(b3, Makeint(b1), "b<<");
            results[13][7] = MyBigIntImp.DoBinaryOperatorMine(b3, Makeint(b2), "b<<");
            results[13][8] = MyBigIntImp.DoBinaryOperatorMine(b3, Makeint(b3), "b<<");
            // ...Op ^
            results[14]    = new BigInteger[9];
            results[14][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b^");
            results[14][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b^");
            results[14][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b^");
            results[14][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b^");
            results[14][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b^");
            results[14][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b^");
            results[14][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b^");
            results[14][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b^");
            results[14][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b^");
            // ...Op |
            results[15]    = new BigInteger[9];
            results[15][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b|");
            results[15][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b|");
            results[15][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b|");
            results[15][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b|");
            results[15][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b|");
            results[15][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b|");
            results[15][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b|");
            results[15][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b|");
            results[15][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b|");
            // ...Op &
            results[16]    = new BigInteger[9];
            results[16][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b&");
            results[16][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b&");
            results[16][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b&");
            results[16][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b&");
            results[16][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b&");
            results[16][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b&");
            results[16][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b&");
            results[16][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b&");
            results[16][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b&");
            // ...Log
            results[17]    = new BigInteger[9];
            results[17][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bLog");
            results[17][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bLog");
            results[17][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bLog");
            results[17][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bLog");
            results[17][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bLog");
            results[17][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bLog");
            results[17][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bLog");
            results[17][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bLog");
            results[17][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bLog");
            // ...GCD
            results[18]    = new BigInteger[9];
            results[18][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bGCD");
            results[18][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bGCD");
            results[18][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bGCD");
            results[18][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bGCD");
            results[18][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bGCD");
            results[18][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bGCD");
            results[18][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bGCD");
            results[18][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bGCD");
            results[18][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bGCD");
            // ...DivRem
            results[20]    = new BigInteger[9];
            results[20][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bDivRem");
            results[20][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bDivRem");
            results[20][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bDivRem");
            results[20][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bDivRem");
            results[20][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bDivRem");
            results[20][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bDivRem");
            results[20][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bDivRem");
            results[20][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bDivRem");
            results[20][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bDivRem");
            // ...Remainder
            results[21]    = new BigInteger[9];
            results[21][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bRemainder");
            results[21][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bRemainder");
            results[21][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bRemainder");
            results[21][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bRemainder");
            results[21][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bRemainder");
            results[21][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bRemainder");
            results[21][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bRemainder");
            results[21][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bRemainder");
            results[21][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bRemainder");
            // ...Op %
            results[22]    = new BigInteger[9];
            results[22][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b%");
            results[22][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b%");
            results[22][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b%");
            results[22][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b%");
            results[22][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b%");
            results[22][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b%");
            results[22][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b%");
            results[22][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b%");
            results[22][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b%");
            // ...Divide
            results[23]    = new BigInteger[9];
            results[23][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bDivide");
            results[23][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bDivide");
            results[23][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bDivide");
            results[23][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bDivide");
            results[23][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bDivide");
            results[23][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bDivide");
            results[23][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bDivide");
            results[23][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bDivide");
            results[23][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bDivide");
            // ...Op /
            results[24]    = new BigInteger[9];
            results[24][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b/");
            results[24][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b/");
            results[24][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b/");
            results[24][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b/");
            results[24][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b/");
            results[24][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b/");
            results[24][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b/");
            results[24][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b/");
            results[24][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b/");
            // ...Multiply
            results[25]    = new BigInteger[9];
            results[25][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bMultiply");
            results[25][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bMultiply");
            results[25][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bMultiply");
            results[25][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bMultiply");
            results[25][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bMultiply");
            results[25][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bMultiply");
            results[25][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bMultiply");
            results[25][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bMultiply");
            results[25][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bMultiply");
            // ...Op *
            results[26]    = new BigInteger[9];
            results[26][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b*");
            results[26][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b*");
            results[26][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b*");
            results[26][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b*");
            results[26][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b*");
            results[26][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b*");
            results[26][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b*");
            results[26][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b*");
            results[26][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b*");
            // ...Subtract
            results[27]    = new BigInteger[9];
            results[27][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bSubtract");
            results[27][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bSubtract");
            results[27][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bSubtract");
            results[27][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bSubtract");
            results[27][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bSubtract");
            results[27][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bSubtract");
            results[27][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bSubtract");
            results[27][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bSubtract");
            results[27][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bSubtract");
            // ...Op -
            results[28]    = new BigInteger[9];
            results[28][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b-");
            results[28][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b-");
            results[28][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b-");
            results[28][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b-");
            results[28][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b-");
            results[28][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b-");
            results[28][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b-");
            results[28][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b-");
            results[28][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b-");
            // ...Add
            results[29]    = new BigInteger[9];
            results[29][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "bAdd");
            results[29][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "bAdd");
            results[29][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "bAdd");
            results[29][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "bAdd");
            results[29][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "bAdd");
            results[29][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "bAdd");
            results[29][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "bAdd");
            results[29][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "bAdd");
            results[29][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "bAdd");
            // ...Op +
            results[30]    = new BigInteger[9];
            results[30][0] = MyBigIntImp.DoBinaryOperatorMine(b1, b1, "b+");
            results[30][1] = MyBigIntImp.DoBinaryOperatorMine(b1, b2, "b+");
            results[30][2] = MyBigIntImp.DoBinaryOperatorMine(b1, b3, "b+");
            results[30][3] = MyBigIntImp.DoBinaryOperatorMine(b2, b1, "b+");
            results[30][4] = MyBigIntImp.DoBinaryOperatorMine(b2, b2, "b+");
            results[30][5] = MyBigIntImp.DoBinaryOperatorMine(b2, b3, "b+");
            results[30][6] = MyBigIntImp.DoBinaryOperatorMine(b3, b1, "b+");
            results[30][7] = MyBigIntImp.DoBinaryOperatorMine(b3, b2, "b+");
            results[30][8] = MyBigIntImp.DoBinaryOperatorMine(b3, b3, "b+");
            // ...ModPow
            results[31]     = new BigInteger[27];
            results[31][0]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b1 < 0 ? -b1 : b1), b1, "tModPow");
            results[31][1]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b1 < 0 ? -b1 : b1), b2, "tModPow");
            results[31][2]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b1 < 0 ? -b1 : b1), b3, "tModPow");
            results[31][3]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b2 < 0 ? -b2 : b2), b1, "tModPow");
            results[31][4]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b2 < 0 ? -b2 : b2), b2, "tModPow");
            results[31][5]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b2 < 0 ? -b2 : b2), b3, "tModPow");
            results[31][6]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b3 < 0 ? -b3 : b3), b1, "tModPow");
            results[31][7]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b3 < 0 ? -b3 : b3), b2, "tModPow");
            results[31][8]  = MyBigIntImp.DoTertanaryOperatorMine(b1, (b3 < 0 ? -b3 : b3), b3, "tModPow");
            results[31][9]  = MyBigIntImp.DoTertanaryOperatorMine(b2, (b1 < 0 ? -b1 : b1), b1, "tModPow");
            results[31][10] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b1 < 0 ? -b1 : b1), b2, "tModPow");
            results[31][11] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b1 < 0 ? -b1 : b1), b3, "tModPow");
            results[31][12] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b2 < 0 ? -b2 : b2), b1, "tModPow");
            results[31][13] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b2 < 0 ? -b2 : b2), b2, "tModPow");
            results[31][14] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b2 < 0 ? -b2 : b2), b3, "tModPow");
            results[31][15] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b3 < 0 ? -b3 : b3), b1, "tModPow");
            results[31][16] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b3 < 0 ? -b3 : b3), b2, "tModPow");
            results[31][17] = MyBigIntImp.DoTertanaryOperatorMine(b2, (b3 < 0 ? -b3 : b3), b3, "tModPow");
            results[31][18] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b1 < 0 ? -b1 : b1), b1, "tModPow");
            results[31][19] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b1 < 0 ? -b1 : b1), b2, "tModPow");
            results[31][20] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b1 < 0 ? -b1 : b1), b3, "tModPow");
            results[31][21] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b2 < 0 ? -b2 : b2), b1, "tModPow");
            results[31][22] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b2 < 0 ? -b2 : b2), b2, "tModPow");
            results[31][23] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b2 < 0 ? -b2 : b2), b3, "tModPow");
            results[31][24] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b3 < 0 ? -b3 : b3), b1, "tModPow");
            results[31][25] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b3 < 0 ? -b3 : b3), b2, "tModPow");
            results[31][26] = MyBigIntImp.DoTertanaryOperatorMine(b3, (b3 < 0 ? -b3 : b3), b3, "tModPow");

            for (int i = 0; i < cycles; i++)
            {
                Worker worker = new Worker(new Random(s_random.Next()), i);
                worker.DoWork();
                Assert.True(worker.Valid, "Verification Failed");
            }
        }
예제 #16
0
 private static String Print(byte[] bytes)
 {
     return MyBigIntImp.Print(bytes);
 }