Exemple #1
0
        static public double Sin(double x, double accuracy)
        {
            bool sign = (x >= 0) ? true : false;

            x = Math.Abs(x);
            while (x >= 2 * Math.PI)
            {
                x -= 2 * Math.PI;
            }
            x = sign ? x : -x;

            double result  = x;
            double element = x;
            double element1;

            int i = 0;

            do
            {
                element1 = (-1) * element * Math.Pow(x, 2) / ((2 * i + 2) * (2 * i + 3));
                result  += element1;
                element  = element1;
                i++;
            } while (Math.Abs(element) > accuracy);

            return(result);
        }
Exemple #2
0
        static public double EPowXClasic(double x, double accuracy)
        {
            if (x == 0)
            {
                return(1);
            }
            bool minus = false;

            if (x < 0)
            {
                minus = true;
                x    *= -1;
            }

            double result = 1 + x;
            double element;

            int i = 2;

            do
            {
                element = Math.Pow(x, i) / Math.Factor(i);
                result += element;
                i++;
            } while (Math.Abs(element) > accuracy);

            if (minus)
            {
                result = 1 / result;
            }

            return(result);
        }