Пример #1
0
        public void RightRoundBlockShiftTest()
        {
            Random random = new Random(1234);

            UInt32[] mantissa = UIntUtil.Random(random, BigUInt <Pow2.N32> .Length, BigUInt <Pow2.N32> .Bits);

            BigUInt <Pow2.N32> v  = new BigUInt <Pow2.N32>(mantissa, enable_clone: false);
            BigInteger         bi = v;

            for (int sft = 0; sft <= BigUInt <Pow2.N32> .Length + 4; sft++)
            {
                BigUInt <Pow2.N32> v_sft = BigUInt <Pow2.N32> .RightRoundBlockShift(v, sft);

                BigInteger bi_sft;
                if (sft > 0)
                {
                    bi_sft = bi >> (sft * UIntUtil.UInt32Bits - 1);

                    if ((bi_sft & 1) == 1)
                    {
                        bi_sft = (bi_sft >> 1) + 1;
                        Console.WriteLine("RoundUp");
                    }
                    else
                    {
                        bi_sft >>= 1;
                        Console.WriteLine("RoundDown");
                    }
                }
                else
                {
                    bi_sft = bi >> (sft * UIntUtil.UInt32Bits);

                    Console.WriteLine("RoundDown");
                }

                Console.WriteLine(sft);
                Console.WriteLine(v.ToHexcode());
                Console.WriteLine(v_sft.ToHexcode());
                Assert.AreEqual(bi_sft, v_sft);

                Console.Write("\n");
            }
        }
Пример #2
0
 public static Accumulator <N> RightRoundBlockShift(Accumulator <N> n, int sft)
 {
     return(new Accumulator <N>(BigUInt <Double <N> > .RightRoundBlockShift(n.value, sft)));
 }
Пример #3
0
 public static Mantissa <N> RightRoundBlockShift(Mantissa <N> n, int sft)
 {
     return(new Mantissa <N>(BigUInt <N> .RightRoundBlockShift(n.value, sft)));
 }