コード例 #1
0
        public void CosHalfPIUnnormalValueTest()
        {
            MultiPrecision <Pow2.N8>[] vs = new MultiPrecision <Pow2.N8>[] {
                MultiPrecision <Pow2.N8> .NaN,
                MultiPrecision <Pow2.N8> .PositiveInfinity,
                MultiPrecision <Pow2.N8> .NegativeInfinity,
            };

            foreach (MultiPrecision <Pow2.N8> v in vs)
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .CosHalfPI(v);

                Assert.IsTrue(y.IsNaN);
            }
        }
コード例 #2
0
        public void CosHalfPILargeValueTest()
        {
            MultiPrecision <Pow2.N8> half = MultiPrecision <Pow2.N8> .Point5;

            MultiPrecision <Pow2.N8>[] borders = new MultiPrecision <Pow2.N8>[] {
                -65538, -65537 - half, -65537, -65536 - half, -65536, -65535 - half,
                65535 + half, 65536, 65536 + half, 65537, 65537 + half, 65538
            };

            foreach (MultiPrecision <Pow2.N8> b in borders)
            {
                List <MultiPrecision <Pow2.N8> > ys = new();

                foreach (MultiPrecision <Pow2.N8> x in TestTool.EnumerateNeighbor(b))
                {
                    MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .CosHalfPI(x);

                    Console.WriteLine(x);
                    Console.WriteLine(x.ToHexcode());
                    Console.WriteLine(y);
                    Console.WriteLine(y.ToHexcode());
                    Console.Write("\n");

                    TestTool.Tolerance(Math.Cos((double)x * Math.PI / 2), y, ignore_sign: true);

                    ys.Add(y);
                }

                if (MultiPrecision <Pow2.N8> .Abs(b % 2) == 1)
                {
                    TestTool.SmoothnessSatisfied(ys, 0.5);
                    TestTool.MonotonicitySatisfied(ys);
                }
                else if (b % 2 == 0)
                {
                    TestTool.NearlyNeighbors(ys, 19);
                    TestTool.SmoothnessSatisfied(ys, 0.5);
                }
                else
                {
                    TestTool.NearlyNeighbors(ys, 20);
                    TestTool.SmoothnessSatisfied(ys, 0.5);
                    TestTool.MonotonicitySatisfied(ys);
                }

                Console.Write("\n");
            }
        }
コード例 #3
0
        public void CosHalfPITest()
        {
            foreach (MultiPrecision <Pow2.N8> x in TestTool.ShortRangeSet <Pow2.N8>())
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .CosHalfPI(x);

                Console.WriteLine(x);
                Console.WriteLine(y);

                TestTool.Tolerance(Math.Cos((double)x * Math.PI / 2), y, minerr: 1e-5, ignore_sign: true);
            }

            for (int x = -31; x <= 31; x += 2)
            {
                MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .CosHalfPI(x);

                Assert.AreEqual(MultiPrecision <Pow2.N8> .Zero, y);
                Assert.AreEqual(Sign.Plus, y.Sign);
            }

            Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits(
                              MultiPrecision <Pow2.N8> .Sqrt2 / 2,
                              MultiPrecision <Pow2.N8> .CosHalfPI(MultiPrecision <Pow2.N8> .Div(1, 2)), 1));

            Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits(
                              MultiPrecision <Pow2.N8> .Sqrt(3) / 2,
                              MultiPrecision <Pow2.N8> .CosHalfPI(MultiPrecision <Pow2.N8> .Div(1, 3)), 1));

            Assert.IsTrue(MultiPrecision <Pow2.N8> .NearlyEqualBits(
                              MultiPrecision <Pow2.N8> .Point5,
                              MultiPrecision <Pow2.N8> .CosHalfPI(MultiPrecision <Pow2.N8> .Div(2, 3)), 1));

            Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits(
                              MultiPrecision <Pow2.N16> .Sqrt2 / 2,
                              MultiPrecision <Pow2.N16> .CosHalfPI(MultiPrecision <Pow2.N16> .Div(1, 2)), 1));

            Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits(
                              MultiPrecision <Pow2.N16> .Sqrt(3) / 2,
                              MultiPrecision <Pow2.N16> .CosHalfPI(MultiPrecision <Pow2.N16> .Div(1, 3)), 1));

            Assert.IsTrue(MultiPrecision <Pow2.N16> .NearlyEqualBits(
                              MultiPrecision <Pow2.N16> .Point5,
                              MultiPrecision <Pow2.N16> .CosHalfPI(MultiPrecision <Pow2.N16> .Div(2, 3)), 1));
        }
コード例 #4
0
        public void CosHalfPIBorderTest()
        {
            MultiPrecision <Pow2.N8> half_n8 = MultiPrecision <Pow2.N8> .Point5;

            MultiPrecision <Pow2.N8>[] borders_n8 = new MultiPrecision <Pow2.N8>[] {
                -4 - half_n8, -4, -3 - half_n8, -3, -2 - half_n8, -2, -1 - half_n8, -1, -0 - half_n8,
                0,
                0 + half_n8, 1, 1 + half_n8, 2, 2 + half_n8, 3, 3 + half_n8, 4, 4 + half_n8
            };

            foreach (MultiPrecision <Pow2.N8> b in borders_n8)
            {
                List <MultiPrecision <Pow2.N8> > ys = new();

                foreach (MultiPrecision <Pow2.N8> x in TestTool.EnumerateNeighbor(b))
                {
                    MultiPrecision <Pow2.N8> y = MultiPrecision <Pow2.N8> .CosHalfPI(x);

                    Console.WriteLine(x);
                    Console.WriteLine(x.ToHexcode());
                    Console.WriteLine(y);
                    Console.WriteLine(y.ToHexcode());
                    Console.Write("\n");

                    TestTool.Tolerance(Math.Cos((double)x * Math.PI / 2), y, ignore_sign: true);

                    ys.Add(y);
                }

                if (MultiPrecision <Pow2.N8> .Abs(b % 2) == 1)
                {
                    TestTool.SmoothnessSatisfied(ys, 1);
                    TestTool.MonotonicitySatisfied(ys);
                }
                else if (b % 2 == 0)
                {
                    TestTool.NearlyNeighbors(ys, 3);
                    TestTool.SmoothnessSatisfied(ys, 0.5);
                }
                else
                {
                    TestTool.NearlyNeighbors(ys, 4);
                    TestTool.SmoothnessSatisfied(ys, 1);
                    TestTool.MonotonicitySatisfied(ys);
                }

                Console.Write("\n");
            }

            MultiPrecision <Pow2.N16> half_n16 = MultiPrecision <Pow2.N16> .Point5;

            MultiPrecision <Pow2.N16>[] borders_n16 = new MultiPrecision <Pow2.N16>[] {
                -4 - half_n16, -4, -3 - half_n16, -3, -2 - half_n16, -2, -1 - half_n16, -1, -0 - half_n16,
                0,
                0 + half_n16, 1, 1 + half_n16, 2, 2 + half_n16, 3, 3 + half_n16, 4, 4 + half_n16
            };

            foreach (MultiPrecision <Pow2.N16> b in borders_n16)
            {
                List <MultiPrecision <Pow2.N16> > ys = new();

                foreach (MultiPrecision <Pow2.N16> x in TestTool.EnumerateNeighbor(b))
                {
                    MultiPrecision <Pow2.N16> y = MultiPrecision <Pow2.N16> .CosHalfPI(x);

                    Console.WriteLine(x);
                    Console.WriteLine(x.ToHexcode());
                    Console.WriteLine(y);
                    Console.WriteLine(y.ToHexcode());
                    Console.Write("\n");

                    TestTool.Tolerance(Math.Cos((double)x * Math.PI / 2), y, ignore_sign: true);

                    ys.Add(y);
                }

                if (MultiPrecision <Pow2.N16> .Abs(b % 2) == 1)
                {
                    TestTool.SmoothnessSatisfied(ys, 1);
                    TestTool.MonotonicitySatisfied(ys);
                }
                else if (b % 2 == 0)
                {
                    TestTool.NearlyNeighbors(ys, 3);
                    TestTool.SmoothnessSatisfied(ys, 0.5);
                }
                else
                {
                    TestTool.NearlyNeighbors(ys, 4);
                    TestTool.SmoothnessSatisfied(ys, 1);
                    TestTool.MonotonicitySatisfied(ys);
                }

                Console.Write("\n");
            }
        }