コード例 #1
0
ファイル: IVSMath.cs プロジェクト: TheLupp/CalcIVSulator
        /// <summary>
        /// Calculates the cosine of a given angle in RADIANS.
        /// </summary>
        /// <param name="a">The angle to calculate the cosine of</param>
        /// <returns>The cosine of the given angle</returns>
        public static double Cosine(double a)
        {
            a %= Math.PI * 2;
            double result = 1;
            bool   add    = false;
            double term   = 0;
            double previousTerm;
            int    i = 2;

            do
            {
                previousTerm = term;
                term         = IVSMath.Power(a, i) / IVSMath.Factorial(i);
                if (add)
                {
                    result += term;
                }
                else
                {
                    result -= term;
                }
                add = !add;
                i  += 2;
            } while (Math.Abs(term - previousTerm) > IVSMath.precision);
            return(result);
        }
コード例 #2
0
ファイル: IVSMath.cs プロジェクト: TheLupp/CalcIVSulator
        /// <summary>
        /// Calculates the tangent of a given angle in RADIANS.
        /// </summary>
        /// <param name="a">The angle to compute the tangent of</param>
        /// <exception cref="ArithmeticException">The specified angle is invalid.</exception>
        /// <exception cref="OverflowException">The result is too large to be stored by a double</exception>
        /// <returns>The tangent of the given angle</returns>
        public static double Tangent(double a)
        {
            if (IVSMath.IsValidTanAngle(a))
            {
                throw new ArithmeticException();
            }

            double result = IVSMath.Sine(a) / IVSMath.Cosine(a);

            if (Double.IsInfinity(result))
            {
                throw new OverflowException();
            }

            return(result);
        }