Esempio n. 1
0
        public void DoubleDoubleTrigIdentities()
        {
            Random rng = new Random(1);

            for (int i = 0; i < 16; i++)
            {
                DoubleDouble x = (2.0 * DoubleDouble.Pi) * (1.0 - 2.0 * DoubleDouble.GetRandomValue(rng));

                DoubleDouble s = DoubleDouble.Sin(x);
                DoubleDouble c = DoubleDouble.Cos(x);
                Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(s * s + c * c, DoubleDouble.One));

                DoubleDouble s2 = DoubleDouble.Sin(2.0 * x);
                Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(s2, 2.0 * s * c));
            }
        }
        public void DoubleDoubleErrorFunctionAgreement()
        {
            foreach (DoubleDouble x in DoubleDoubleTest.GetRandomDoubleDoubles(1.0E-2, 1.0E2, 8))
            {
                DoubleDouble xErf         = AdvancedDoubleDoubleMath.Erf(x);
                double       xErfAsDouble = (double)xErf;

                double xAsDouble    = (double)x;
                double xAsDoubleErf = AdvancedMath.Erf(xAsDouble);

                Assert.IsTrue(TestUtilities.IsNearlyEqual(xErfAsDouble, xAsDoubleErf));

                DoubleDouble xErfc = AdvancedDoubleDoubleMath.Erfc(x);
                Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(xErf + xErfc, DoubleDouble.One));
            }
        }
Esempio n. 3
0
        public void DoubleDoubleTrigSpecialCases()
        {
            Assert.IsTrue(DoubleDouble.Sin(0.0) == DoubleDouble.Zero);
            Assert.IsTrue(DoubleDouble.Cos(0.0) == DoubleDouble.One);

            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Sin(DoubleDouble.Pi / 6), DoubleDouble.One / 2));
            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Cos(DoubleDouble.Pi / 6), DoubleDouble.Sqrt(3) / 2));

            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Cos(DoubleDouble.Pi / 5), (1 + DoubleDouble.Sqrt(5)) / 4));

            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Sin(DoubleDouble.Pi / 4), DoubleDouble.One / DoubleDouble.Sqrt(2)));
            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Cos(DoubleDouble.Pi / 4), DoubleDouble.One / DoubleDouble.Sqrt(2)));

            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Cos(DoubleDouble.Pi / 3), DoubleDouble.One / 2));
            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Sin(DoubleDouble.Pi / 3), DoubleDouble.Sqrt(3) / 2));

            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Sin(DoubleDouble.Pi / 2), DoubleDouble.One));

            Assert.IsTrue(DoubleDoubleTest.IsNearlyEqual(DoubleDouble.Cos(DoubleDouble.Pi), -DoubleDouble.One));

            // Not testing zeros because of need to distingish very small values
        }