Example #1
0
        /// <summary>
        /// Computes the cosine of the given value to full significance over the full range of arguments.
        /// </summary>
        /// <param name="x">The argument.</param>
        /// <returns>The value of sin(x).</returns>
        /// <remarks>
        /// <para>For an explanaition of this method, see the remarks for the <see cref="MoreMath.Sin"/> method.</para>
        /// </remarks>
        public static double Cos(double x)
        {
            // Ensure x is non-negative; this is easy because cosine is an even function.
            if (x < 0.0)
            {
                x = -x;
            }

            if (x < 1.0)
            {
                // If x is small enough not to cross a zero, use the built-in function
                return(Math.Cos(x));
            }
            else if (x < RangeReduction.xLimit)
            {
                // If x is in the intermediate region, try the built-in function but switch to our range-reduction
                // algorithm if the result is too small.
                double y  = Math.Cos(x);
                double ym = x / RangeReduction.xLimit;
                if (Math.Abs(y) < ym)
                {
                    return(RangeReduction.Cos(x));
                }
                else
                {
                    return(y);
                }
            }
            else
            {
                // If x is beyond the range of the built-in function eintirely, use our range-reduction algorithm
                return(RangeReduction.Cos(x));
            }
        }
Example #2
0
        internal static double CosPi(double x)
        {
            long   y0;
            double y1;

            RangeReduction.ReduceByOnes(2.0 * x, out y0, out y1);
            return(RangeReduction.Cos(y0, y1));
        }
Example #3
0
 /// <summary>
 /// Computes the cosine of the given multiple of &#x3C0;.
 /// </summary>
 /// <param name="x">The argument.</param>
 /// <returns>The value of cos(<paramref name="x"/>&#x3C0;).</returns>
 /// <remarks>
 /// <para>For an explanation of why and when to use this function,
 /// see <see cref="SinPi(double)"/>.</para>
 /// </remarks>
 /// <seealso cref="SinPi(double)"/>
 public static double CosPi(double x)
 {
     RangeReduction.ReduceByOnes(2.0 * x, out long y0, out double y1);
     return(RangeReduction.Cos(y0, y1));
 }