Пример #1
0
        public void Multiply_multiplicationOfnumbers_SideTestOfToString()
        {
            //Act
            var result = a.Multiply(b);

            //Assert
            Assert.AreEqual((unchecked ((sbyte)(24 * 42))).ToString(), result.ToString()); //result test
        }
Пример #2
0
        public void Q8_24_MultiplyNoOverflow()
        {
            var pos = new Fixed <Q8_24>(2);
            var neg = new Fixed <Q8_24>(-16);

            var posRes = pos.Multiply(pos);
            var posNeg = pos.Multiply(neg);
            var negPos = neg.Multiply(pos);
            var negRes = neg.Multiply(neg);

            Assert.AreEqual("4", posRes.ToString());
            Assert.AreEqual("-32", posNeg.ToString());
            Assert.AreEqual("-32", negPos.ToString());
        }
Пример #3
0
 public void Q8_24Test()
 {
     for (int i = 0; i < 1000; i++)
     {
         f9 = f7.Multiply(f8);
     }
 }
Пример #4
0
 public void Q16_16Test()
 {
     for (int i = 0; i < 1000; i++)
     {
         f6 = f4.Multiply(f5);
     }
 }
Пример #5
0
 public void Q24_8Test()
 {
     for (int i = 0; i < 1000; i++)
     {
         f3 = f1.Multiply(f2);
     }
 }
Пример #6
0
        public void MultiplicationTestingSameTypesQ24_8(int in1, int in2, string exp)
        {
            var f1 = new Fixed <Q24_8>(in1);
            var f2 = new Fixed <Q24_8>(in2);

            Assert.Equal(exp, f1.Multiply(f2).ToString());
        }
Пример #7
0
        public static void Multiply_multiplicationOfnumbers_negativeResult_SideTestOfToString(Fixed <Q> a, Fixed <Q> b)
        {
            //Act
            var result = a.Multiply(b);

            //Assert
            Assert.AreEqual((24 * -42).ToString(), result.ToString()); //result test
        }
Пример #8
0
        public void Multiplication3()
        {
            var f1 = new Fixed <Q24_8>(3);
            var f2 = new Fixed <Q24_8>(-4);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual("-12", f3.ToString());
        }
Пример #9
0
        public void TestMultiplication(int intValue1, int intValue2, string expectedResult)
        {
            f1 = new Fixed <Q>(intValue1);
            f2 = new Fixed <Q>(intValue2);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual(expectedResult, f3.ToString());
        }
Пример #10
0
        public void test3()
        {
            var f1 = new Fixed <Q24_8>(3);
            var f2 = new Fixed <Q24_8>(2);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual(f3.ToString(), "6");
        }
Пример #11
0
        public void test4()
        {
            var f1 = new Fixed <Q8_24>(19);
            var f2 = new Fixed <Q8_24>(13);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual(f3.ToString(), "-9");
        }
Пример #12
0
        public void Multiply()
        {
            var f1 = new Fixed <Q24_8>(3);
            var f2 = new Fixed <Q24_8>(2);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual("6", f3.ToString());
        }
Пример #13
0
        public void Multiplication1()
        {
            var f1 = new Fixed <Q8_24>(3);
            var f2 = new Fixed <Q8_24>(4);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual("12", f3.ToString());
        }
Пример #14
0
        public void Q24_8_MultiplyOverflow()
        {
            var lhs = new Fixed <Q24_8>(Int32.MaxValue);

            var res = lhs.Multiply(lhs);

            Assert.AreEqual("1", res.ToString());
        }
Пример #15
0
        public void Q8_24_MultiplyOverflow()
        {
            var lhs = new Fixed <Q8_24>(16);

            var res = lhs.Multiply(lhs);

            Assert.AreEqual("0", res.ToString());
        }
Пример #16
0
        public void MultiplyHigher()
        {
            var f1 = new Fixed <Q24_8>(19);
            var f2 = new Fixed <Q24_8>(13);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual("247", f3.ToString());
        }
Пример #17
0
        public void Q24_8_MultiplyDecimal()
        {
            var lhs = new Fixed <Q24_8>(10).Divide(new Fixed <Q24_8>(4));

            var res = lhs.Multiply(new Fixed <Q24_8>(8));

            Assert.AreEqual("20", res.ToString());
        }
Пример #18
0
        public void Multiplication2()
        {
            var f1 = new Fixed <Q16_16>(3);
            var f2 = new Fixed <Q16_16>(0);
            var f3 = f1.Multiply(f2);

            Assert.AreEqual("0", f3.ToString());
        }
Пример #19
0
        public Fixed <T> Multiply <T>(int a, int b) where T : IArithmetics, new()
        {
            var aFixed      = new Fixed <T>(a);
            var bFixed      = new Fixed <T>(b);
            var resultFixed = aFixed.Multiply(bFixed);

            Assert.AreEqual(Math.Round(a * (double)b, roundDeximalCount),
                            Math.Round(resultFixed, roundDeximalCount));
            return(resultFixed);
        }
Пример #20
0
        public void Multiply_multiplicationOfnumbers_SideTestOfToString()
        {
            //Arrange
            Fixed <Q8_24> a = new Fixed <Q8_24>(3);
            Fixed <Q8_24> b = new Fixed <Q8_24>(42);

            //Act
            var result = a.Multiply(b);

            //Assert
            Assert.AreEqual((3 * 42).ToString(), result.ToString()); //result test
        }
Пример #21
0
        public void Multiply_multiplicationOfnumbers_negativeResult_SideTestOfToString()
        {
            //Arrange
            Fixed <Q24_8> a = new Fixed <Q24_8>(24);
            Fixed <Q24_8> b = new Fixed <Q24_8>(-42);

            //Act
            var result = a.Multiply(b);

            //Assert
            Assert.AreEqual((24 * -42).ToString(), result.ToString()); //result test
        }
Пример #22
0
        public void MultBigQ8_24()
        {
            // Too big numbers
            int a      = 7;
            int b      = 50;
            var aFixed = new Fixed <Q8_24>(a);
            var bFixed = new Fixed <Q8_24>(b);

            var negAFixed = bFixed.Multiply(aFixed);

            //Assert.AreEqual(a * b, Math.Round(negAFixed, roundDeximalCount));
            Assert.Inconclusive();
        }
Пример #23
0
        public void Fixed_ToString()
        {
            var f = new Fixed <T>(67);

            Assert.AreEqual(((double)f).ToString(), f.ToString());
            f = f.Add(new Fixed <T>(48));
            Assert.AreEqual(((double)f).ToString(), f.ToString());
            f = f.Subtract(new Fixed <T>(85));
            Assert.AreEqual(((double)f).ToString(), f.ToString());
            f = f.Multiply(new Fixed <T>(6));
            Assert.AreEqual(((double)f).ToString(), f.ToString());
            f = f.Divide(new Fixed <T>(7));
            Assert.AreEqual(((double)f).ToString(), f.ToString());

            f = new Fixed <T>(-95);
            Assert.AreEqual(((double)f).ToString(), f.ToString());
            f = f.Divide(new Fixed <T>(11));
            Assert.AreEqual(((double)f).ToString(), f.ToString());
            f = new Fixed <T>(0);
            Assert.AreEqual("0", f.ToString());
        }
Пример #24
0
 public void Q16_16Test()
 {
     var f1 = new Fixed <Q16_16>(a);
     var f2 = new Fixed <Q16_16>(b);
     var f3 = f1.Multiply(f2);
 }
Пример #25
0
 public void Q24_8Test()
 {
     var f1 = new Fixed <Q24_8>(a);
     var f2 = new Fixed <Q24_8>(b);
     var f3 = f1.Multiply(f2);
 }
Пример #26
0
        static void Main(string[] args)
        {
            Console.WriteLine("Q24_8:");
            {
                var f1 = new Fixed <Q24_8>(3);
                Console.WriteLine($"3: {f1}");

                var f2 = new Fixed <Q24_8>(2);
                var f3 = f1.Add(f2);
                Console.WriteLine($"3 + 2: {f3}");

                f3 = f1.Multiply(f2);
                Console.WriteLine($"3 * 2: {f3}");

                f1 = new Fixed <Q24_8>(19);
                f2 = new Fixed <Q24_8>(13);
                f3 = f1.Multiply(f2);
                Console.WriteLine($"19 * 13: {f3}");

                f1 = new Fixed <Q24_8>(3);
                f2 = new Fixed <Q24_8>(2);
                f3 = f1.Divide(f2);
                Console.WriteLine($"3 / 2: {f3}");

                f1 = new Fixed <Q24_8>(248);
                f2 = new Fixed <Q24_8>(10);
                f3 = f1.Divide(f2);
                Console.WriteLine($"248 / 10: {f3}");

                f1 = new Fixed <Q24_8>(625);
                f2 = new Fixed <Q24_8>(1000);
                f3 = f1.Divide(f2);
                Console.WriteLine($"625 / 1000: {f3}");
            }

            //

            Console.WriteLine();
            Console.WriteLine("Q16_16:");
            {
                var f1 = new Fixed <Q16_16>(3);
                Console.WriteLine($"3: {f1}");

                var f2 = new Fixed <Q16_16>(2);
                var f3 = f1.Add(f2);
                Console.WriteLine($"3 + 2: {f3}");

                f3 = f1.Multiply(f2);
                Console.WriteLine($"3 * 2: {f3}");

                f1 = new Fixed <Q16_16>(19);
                f2 = new Fixed <Q16_16>(13);
                f3 = f1.Multiply(f2);
                Console.WriteLine($"19 * 13: {f3}");

                f1 = new Fixed <Q16_16>(248);
                f2 = new Fixed <Q16_16>(10);
                f3 = f1.Divide(f2);
                Console.WriteLine($"248 / 10: {f3}");

                f1 = new Fixed <Q16_16>(625);
                f2 = new Fixed <Q16_16>(1000);
                f3 = f1.Divide(f2);
                Console.WriteLine($"625 / 1000: {f3}");
            }

            //

            Console.WriteLine();
            Console.WriteLine("Q8_24:");
            {
                var f1 = new Fixed <Q8_24>(3);
                var f2 = new Fixed <Q8_24>(2);
                var f3 = f1.Add(f2);
                Console.WriteLine($"3 + 2: {f3}");

                f3 = f1.Multiply(f2);
                Console.WriteLine($"3 * 2: {f3}");

                f1 = new Fixed <Q8_24>(19);
                f2 = new Fixed <Q8_24>(13);
                f3 = f1.Multiply(f2);
                Console.WriteLine($"19 * 13: {f3}");

                f1 = new Fixed <Q8_24>(248);
                f2 = new Fixed <Q8_24>(10);
                f3 = f1.Divide(f2);
                Console.WriteLine($"248 / 10: {f3}");

                f1 = new Fixed <Q8_24>(625);
                f2 = new Fixed <Q8_24>(1000);
                f3 = f1.Divide(f2);
                Console.WriteLine($"625 / 1000: {f3}");
            }
        }
Пример #27
0
        static void Main(string[] args)
        {
            #region Operations

            Console.WriteLine("Q24_8:");
            {
                var f1 = new Fixed <Q24_8>(3);
                Console.WriteLine($"3: {f1}");

                var f2 = new Fixed <Q24_8>(2);
                var f3 = f1.Add(f2);
                Console.WriteLine($"3 + 2: {f3}");

                f3 = f1.Multiply(f2);
                Console.WriteLine($"3 * 2: {f3}");

                f1 = new Fixed <Q24_8>(19);
                f2 = new Fixed <Q24_8>(13);
                f3 = f1.Multiply(f2);
                Console.WriteLine($"19 * 13: {f3}");

                f1 = new Fixed <Q24_8>(3);
                f2 = new Fixed <Q24_8>(2);
                f3 = f1.Divide(f2);
                Console.WriteLine($"3 / 2: {f3}");

                f1 = new Fixed <Q24_8>(248);
                f2 = new Fixed <Q24_8>(10);
                f3 = f1.Divide(f2);
                Console.WriteLine($"248 / 10: {f3}");

                f1 = new Fixed <Q24_8>(625);
                f2 = new Fixed <Q24_8>(1000);
                f3 = f1.Divide(f2);
                Console.WriteLine($"625 / 1000: {f3}");
            }

            Console.WriteLine();
            Console.WriteLine("Q16_16:");
            {
                var f1 = new Fixed <Q16_16>(3);
                Console.WriteLine($"3: {f1}");

                var f2 = new Fixed <Q16_16>(2);
                var f3 = f1.Add(f2);
                Console.WriteLine($"3 + 2: {f3}");

                f3 = f1.Multiply(f2);
                Console.WriteLine($"3 * 2: {f3}");

                f1 = new Fixed <Q16_16>(19);
                f2 = new Fixed <Q16_16>(13);
                f3 = f1.Multiply(f2);
                Console.WriteLine($"19 * 13: {f3}");

                f1 = new Fixed <Q16_16>(248);
                f2 = new Fixed <Q16_16>(10);
                f3 = f1.Divide(f2);
                Console.WriteLine($"248 / 10: {f3}");

                f1 = new Fixed <Q16_16>(625);
                f2 = new Fixed <Q16_16>(1000);
                f3 = f1.Divide(f2);
                Console.WriteLine($"625 / 1000: {f3}");
            }

            Console.WriteLine();
            Console.WriteLine("Q8_24:");
            {
                var f1 = new Fixed <Q8_24>(3);
                var f2 = new Fixed <Q8_24>(2);
                var f3 = f1.Add(f2);
                Console.WriteLine($"3 + 2: {f3}");

                f3 = f1.Multiply(f2);
                Console.WriteLine($"3 * 2: {f3}");

                f1 = new Fixed <Q8_24>(19);
                f2 = new Fixed <Q8_24>(13);
                f3 = f1.Multiply(f2);
                Console.WriteLine($"19 * 13: {f3}");

                f1 = new Fixed <Q8_24>(248);
                f2 = new Fixed <Q8_24>(10);
                f3 = f1.Divide(f2);
                Console.WriteLine($"248 / 10: {f3}");

                f1 = new Fixed <Q8_24>(625);
                f2 = new Fixed <Q8_24>(1000);
                f3 = f1.Divide(f2);
                Console.WriteLine($"625 / 1000: {f3}");
            }

            #endregion

            #region Gaussian Elimination

            Console.WriteLine();
            Console.WriteLine("Gaussian elimination:");

            Console.WriteLine();
            Console.WriteLine("Q8_24:");

            var matrixArr = RandomArray.GetRandomMatrixArray(10, 100);
            var matrix    = new Matrix(matrixArr, 10);
            Console.WriteLine("Original matrix:");
            matrix.Print();

            Console.WriteLine("After elimination:");
            matrix.EliminateRows();
            matrix.Print();

            #endregion

            var summary = BenchmarkRunner.Run <FixedTest>();
        }
Пример #28
0
 public void Q8_24Test()
 {
     var f1 = new Fixed <Q8_24>(a);
     var f2 = new Fixed <Q8_24>(b);
     var f3 = f1.Multiply(f2);
 }