public void RightRoundShiftTest() { 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> .Bits + 4; sft++) { BigUInt <Pow2.N32> v_sft = BigUInt <Pow2.N32> .RightRoundShift(v, sft); BigInteger bi_sft; if (sft > 0) { bi_sft = bi >> (sft - 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; Console.WriteLine("RoundDown"); } Console.WriteLine(sft); Console.WriteLine(v.ToHexcode()); Console.WriteLine(v_sft.ToHexcode()); Assert.AreEqual(bi_sft, v_sft); Console.Write("\n"); } }
public static Accumulator <N> RightRoundShift(Accumulator <N> n, int sft) { return(new Accumulator <N>(BigUInt <Double <N> > .RightRoundShift(n.value, sft))); }
public static Mantissa <N> RightRoundShift(Mantissa <N> n, int sft) { return(new Mantissa <N>(BigUInt <N> .RightRoundShift(n.value, sft))); }