Пример #1
0
        public void TestMultiply()
        {
            var a = Fixed.Parse("10.3");
            var b = Fixed.Parse("3.2");

            var mul = a * b;

            AssertApproximately(Fixed.Parse("32.96"), mul);
        }
Пример #2
0
        public void TestSubtract()
        {
            var a = Fixed.Parse("10.3");
            var b = Fixed.Parse("3.2");

            var sub = a - b;
            var r   = Fixed.Parse("7.1");

            AssertApproximately(r, sub);
        }
Пример #3
0
        public void TestDivide()
        {
            var a = Fixed.Parse("10.3");
            var b = Fixed.Parse("3.2");

            var div = a / b;
            var r   = Fixed.Parse("3.21875");

            AssertApproximately(r, div);
        }
Пример #4
0
        public void TestSqrt()
        {
            var a = Fixed.FromInt(9);
            var r = Fixed.FromInt(3);

            AssertApproximately(r, FMath.Sqrt(a));

            a = Fixed.Parse("1546.564654");
            r = Fixed.Parse("39.326386");
            AssertApproximately(r, FMath.Sqrt(a));
        }
Пример #5
0
        public void TestAdd()
        {
            var a = Fixed.Parse("10.3");
            var b = Fixed.Parse("3.2");

            var sum = a + b;

            AssertApproximately(Fixed.Parse("13.5"), sum);

            sum = a + 3;
            AssertApproximately(Fixed.Parse("13.3"), sum);

            sum = -5 + b;
            AssertApproximately(Fixed.Parse("-1.8"), sum);
        }
Пример #6
0
        public void TestTan()
        {
            var deg2Rad = Fixed.FromFloat((float)(Math.PI / 180));
            var a       = Fixed.FromInt(45) * deg2Rad;
            var r       = Fixed.FromInt(1);

            AssertApproximately(r, FMath.Tan(a));

            a = Fixed.FromInt(0) * deg2Rad;
            r = Fixed.FromInt(0);
            AssertApproximately(r, FMath.Tan(a));

            a = Fixed.FromInt(37) * deg2Rad;
            r = Fixed.Parse("0.75355405");
            AssertApproximately(r, FMath.Tan(a));
        }
Пример #7
0
        public void TestCos()
        {
            var deg2Rad = Fixed.FromFloat((float)(Math.PI / 180));
            var a       = Fixed.FromInt(90) * deg2Rad;
            var r       = Fixed.FromInt(0);

            AssertApproximately(r, FMath.Cos(a));

            a = Fixed.FromInt(0) * deg2Rad;
            r = Fixed.FromInt(1);
            AssertApproximately(r, FMath.Cos(a));

            a = Fixed.FromInt(37) * deg2Rad;
            r = Fixed.Parse("0.79863551");
            AssertApproximately(r, FMath.Cos(a));
        }
Пример #8
0
        public void TestSin()
        {
            var deg2Rad = Fixed.FromFloat((float)(Math.PI / 180));
            var a       = Fixed.FromInt(90) * deg2Rad;
            var r       = Fixed.FromInt(1);

            AssertApproximately(r, FMath.Sin(a));

            a = Fixed.FromInt(0) * deg2Rad;
            r = Fixed.FromInt(0);
            AssertApproximately(r, FMath.Sin(a));

            a = Fixed.FromInt(37) * deg2Rad;
            r = Fixed.Parse("0.60181502");
            AssertApproximately(r, FMath.Sin(a));
        }
Пример #9
0
        public void TestFactory()
        {
            var a = Fixed.FromInt(10);

            Assert.AreEqual(Fixed.FromInt(10), a);

            var b = Fixed.FromFloat(3.2f);

            Assert.AreEqual(Fixed.FromFloat(3.2f), b);

            var c = Fixed.Parse("6.3");

            AssertApproximately(Fixed.FromFraction(63, 10), c);

            var d = Fixed.FromFraction(3141592, 1000000);

            AssertApproximately(Fixed.FromFloat(3.141592f), d);
        }
Пример #10
0
        public void TestParseFloat()
        {
            var f = Fixed.Parse("000.0000");

            AssertApproximately(Fixed.Zero, f);

            f = Fixed.Parse("1.4567");
            AssertApproximately(Fixed.FromFloat(1.4567f), f);

            f = Fixed.Parse("-1.4831");
            AssertApproximately(Fixed.FromFloat(-1.4831f), f);

            f = Fixed.Parse("16777216.1345654");
            AssertApproximately(Fixed.FromFloat(16777216), f);

            f = Fixed.Parse("-16777216.1345654");
            AssertApproximately(Fixed.FromFloat(-16777216), f);
        }
Пример #11
0
        public void TestParseInt()
        {
            var n = Fixed.Parse("0");

            Assert.AreEqual(Fixed.Zero, n);

            n = Fixed.Parse("1");
            Assert.AreEqual(Fixed.One, n);

            n = Fixed.Parse("-1");
            Assert.AreEqual(Fixed.FromInt(-1), n);

            n = Fixed.Parse("16777216");
            Assert.AreEqual(Fixed.FromInt(16777216), n);

            n = Fixed.Parse("-16777216");
            Assert.AreEqual(Fixed.FromInt(-16777216), n);
        }