Ejemplo n.º 1
0
        public void TestShifts1()
        {
            SLongIntB A = new SLongIntB("-98276598235872");
            SLongIntB B = new SLongIntB(A);

            for (int i = 0; i < 10; ++i)
            {
                A.Shr();
                B /= 2;
                Assert.AreEqual(A, B);
            }

            for (int i = 0; i < 10; ++i)
            {
                A.Shl();
                B *= 2;
                Assert.AreEqual(A, B);
            }
        }
Ejemplo n.º 2
0
        public static void TwoFact(SLongIntB A, out SLongIntB u, out int k)
        {
            k = 0;
            u = new SLongIntB(A);

            if (A == 0)
                return;

            while (LongMath.IsEven(u))
            {
                ++k;
                u.Shr();
            }
        }
Ejemplo n.º 3
0
        public void TestShiftRight()
        {
            SLongIntB N = new SLongIntB("2945729752935981200000005151659293467923476293623");
            RandomLong rand = new RandomLong((ulong)DateTime.Now.Millisecond);

            for (int i = 0; i < 1000; ++i)
            {
                SLongIntB temp1 = new SLongIntB(rand.Next(N), ConstructorMode.Assign);
                SLongIntB temp3 = new SLongIntB(temp1);

                temp1.Shr();

                SLongIntB temp2 = new SLongIntB(temp1);
                temp2.Shl();

                Assert.AreEqual(temp1 * 2, temp2);
                Assert.AreEqual(temp1, temp3 / 2);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Divides input number by 2 while can
        /// </summary>
        /// <param name="A">Input number</param>
        /// <param name="k">Number of times, that value is diveded by 2</param>
        public static void SelfTwoFact(SLongIntB A, out int k)
        {
            k = 0;

            if (A == 0)
                return;

            while (LongMath.IsEven(A))
            {
                A.Shr();
                ++k;
            }
        }