Beispiel #1
0
        public void Pow()
        {
            void Test(double x, double p) => Assert2.AreNearlyEqual(Math.Pow(x, p), ElementaryFunctions.Pow(x, p));

            Test(2.0, 3.0);
            Test(2.0, 0.5);
            Test(Math.PI, Math.E);
        }
Beispiel #2
0
        public void Log()
        {
            void Test(double x) => Assert2.AreNearlyEqual(Math.Log(x), ElementaryFunctions.Log(x));

            // x=1 から離れるほど誤差が大きくなります。
            Test(1.0);
            Test(2.0);
            Test(3.0);
            Test(0.5);
            Test(Math.E);
        }
Beispiel #3
0
        public void Exp()
        {
            void Test(double x) => Assert2.AreNearlyEqual(Math.Exp(x), ElementaryFunctions.Exp(x));

            // x=0 から離れるほど誤差が大きくなります。
            Test(1.0);
            Test(-1.0);
            Test(0.5);
            Test(2.0);
            Test(Math.PI);
        }
Beispiel #4
0
        public void Log_b()
        {
            void Test(double x, double b) => Assert2.AreNearlyEqual(Math.Log(x, b), ElementaryFunctions.Log(x, b), -9);

            Test(1.0, 2);
            Test(2.0, 2);
            Test(0.5, 2);
            Test(1.0, 10);
            Test(2.0, 10);
            Test(0.5, 10);
            Test(Math.E, Math.E);
        }
Beispiel #5
0
        public void Cbrt()
        {
            void Test(double x) => Assert2.AreNearlyEqual(Math.Pow(x, 1.0 / 3), ElementaryFunctions.Cbrt(x));

            Test(1.0);
            Test(2.0);
            Test(3.0);
            Test(127.0);
            Test(123456789);
            Test(0.00000001);
            Test(0.000000001);
        }
Beispiel #6
0
        public void Tan()
        {
            void Test(double expected, double x) => Assert2.AreNearlyEqual(expected, ElementaryFunctions.Tan(x));

            Test(Math.Sqrt(3), Math.PI / 3);
            Test(1.0, Math.PI / 4);
            Test(1 / Math.Sqrt(3), Math.PI / 6);
            Test(0.0, 0);
            Test(-1 / Math.Sqrt(3), -Math.PI / 6);
            Test(-1.0, -Math.PI / 4);
            Test(-Math.Sqrt(3), -Math.PI / 3);

            Test(2 - Math.Sqrt(3), Math.PI / 12);
        }
Beispiel #7
0
        public void Inverse()
        {
            void Test(double x) => Assert2.AreNearlyEqual(1 / x, ElementaryFunctions.Inverse(x));

            Test(1.0);
            Test(0.001);
            Test(0.00081);
            Test(0.15);
            Test(0.2);
            Test(3.0);
            Test(7.0);
            Test(256.0);
            Test(12345);
        }
Beispiel #8
0
        public void Cos()
        {
            void Test(double expected, double x) => Assert2.AreNearlyEqual(expected, ElementaryFunctions.Cos(x));

            Test(1.0, 0);
            Test(Math.Sqrt(3) / 2, Math.PI / 6);
            Test(Math.Sqrt(2) / 2, Math.PI / 4);
            Test(0.5, Math.PI / 3);
            Test(0.0, Math.PI / 2);
            Test(-0.5, Math.PI * 2 / 3);
            Test(-Math.Sqrt(2) / 2, Math.PI * 3 / 4);
            Test(-Math.Sqrt(3) / 2, Math.PI * 5 / 6);
            Test(-1.0, Math.PI);

            Test((Math.Sqrt(6) + Math.Sqrt(2)) / 4, Math.PI / 12);
        }
Beispiel #9
0
 public void GetE() => Assert2.AreNearlyEqual(Math.E, ElementaryFunctions.GetE());