Пример #1
0
        public static void Divide(ref UInt64_ left, uint right, out UInt64_ result)
        {
            uint remainder = 0;

            result.A = DivideWithRemainder(left.A, right, ref remainder);
            result.B = DivideWithRemainder(left.B, right, ref remainder);
        }
Пример #2
0
        public static void TwosComplement(ref UInt64_ value, out UInt64_ result)
        {
            OnesComplement(ref value, out result);
            var one = (UInt64_)1;

            Add(ref result, ref one, out result);
        }
Пример #3
0
        public void Divide()
        {
            var     top = (UInt64_)(2L * uint.MaxValue);
            UInt64_ result;

            UInt64_.Divide(ref top, uint.MaxValue, out result);
            Assert.AreEqual(2, (ulong)result);
        }
Пример #4
0
        public void Add()
        {
            var     int32Max = (UInt64_)uint.MaxValue;
            UInt64_ result;

            UInt64_.Add(ref int32Max, ref int32Max, out result);
            Assert.AreEqual((ulong)uint.MaxValue + uint.MaxValue, (ulong)result);
        }
Пример #5
0
        public void Multiply()
        {
            var     int32Max = (UInt64_)uint.MaxValue;
            var     two      = (UInt64_)2;
            UInt64_ result;

            UInt64_.Multiply(ref int32Max, 2, out result);
            Assert.AreEqual((ulong)uint.MaxValue * 2, (ulong)result);
        }
Пример #6
0
        public void Subtract()
        {
            var     a = (UInt64_)((ulong)uint.MaxValue + 10);
            var     b = (UInt64_)uint.MaxValue;
            UInt64_ result;

            UInt64_.Subtract(ref a, ref b, out result);
            Assert.AreEqual(10, (ulong)result);
        }
Пример #7
0
        public static void Modulo(ref UInt64_ left, ref uint right, out uint result)
        {
            uint    remainder = 0;
            UInt64_ division  = default;

            division.A = DivideWithRemainder(left.A, right, ref remainder);
            division.B = DivideWithRemainder(left.B, right, ref remainder);
            result     = remainder;
        }
Пример #8
0
        public static void Multiply(ref UInt64_ left, uint right, out UInt64_ result)
        {
            uint carry = 0;

            result.B = MultiplyWithCarry(left.B, right, ref carry);
            result.A = MultiplyWithCarry(left.A, right, ref carry);

            // Throw an overflow error if checked.
            carry += uint.MaxValue;
        }
Пример #9
0
 public static void Subtract(ref UInt64_ left, ref UInt64_ right, out UInt64_ result)
 {
     TwosComplement(ref right, out result);
     Add(ref left, ref result, out result);
 }
Пример #10
0
 public static void OnesComplement(ref UInt64_ value, out UInt64_ result)
 {
     result.A = ~value.A;
     result.B = ~value.B;
 }