Pow() публичный Метод

public Pow ( int exp ) : BigInteger
exp int
Результат BigInteger
Пример #1
0
		static BigInteger()
		{
            Zero = new BigInteger(0, ZeroMagnitude, false);
            Zero.nBits = 0; Zero.nBitLength = 0;

            SMALL_CONSTANTS[0] = Zero;
            for (uint i = 1; i < SMALL_CONSTANTS.Length; ++i)
            {
                SMALL_CONSTANTS[i] = CreateUValueOf(i);
            }

            One = SMALL_CONSTANTS[1];
            Two = SMALL_CONSTANTS[2];
            Three = SMALL_CONSTANTS[3];
            Ten = SMALL_CONSTANTS[10];

            radix2 = ValueOf(2);
            radix2E = radix2.Pow(chunk2);

            radix8 = ValueOf(8);
            radix8E = radix8.Pow(chunk8);

            radix10 = ValueOf(10);
		    radix10E = radix10.Pow(chunk10);

            radix16 = ValueOf(16);
            radix16E = radix16.Pow(chunk16);

            primeProducts = new int[primeLists.Length];

			for (int i = 0; i < primeLists.Length; ++i)
			{
				int[] primeList = primeLists[i];
				int product = primeList[0];
				for (int j = 1; j < primeList.Length; ++j)
				{
					product *= primeList[j];
				}
				primeProducts[i] = product;
			}
		}
Пример #2
0
		public void TestPow()
		{
			Assert.AreEqual(one, zero.Pow(0));
			Assert.AreEqual(zero, zero.Pow(123));
			Assert.AreEqual(one, one.Pow(0));
			Assert.AreEqual(one, one.Pow(123));

			BigInteger n = new BigInteger("1234567890987654321");
			BigInteger result = one;

			for (int i = 0; i < 10; ++i)
			{
				try
				{
					val(i).Pow(-1);
					Assert.Fail("expected ArithmeticException");
				}
				catch (ArithmeticException) {}

				Assert.AreEqual(result, n.Pow(i));

				result = result.Multiply(n);
			}
		}