コード例 #1
0
        /// <summary>
        /// Compares two numbers given some amount of allowed error.
        /// </summary>
        /// <param name="x">The first number.</param>
        /// <param name="y">The second number.</param>
        /// <param name="epsilon">The amount of error allowed when checking for equality.</param>
        /// <returns>0 if x equals y, -1 if x is less than y, 1 if x is greater than y.</returns>
        public static int CompareTo(float x, float y, double epsilon)
        {
            if (Precision.Equals(x, y, epsilon))
            {
                return(0);
            }

            return(x < y
                ? -1
                : 1);
        }
コード例 #2
0
        /// <summary>
        /// Compares two numbers given some amount of allowed distance.
        /// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
        /// </summary>
        /// <param name="x">The first number.</param>
        /// <param name="y">The second number.</param>
        /// <param name="maxUlp">The number of discreet floating point values that are allowed between the two values.</param>
        /// <returns>0 if x equals y, -1 if x is less than y, 1 if x is greater than y.</returns>
        public static int CompareTo(double x, double y, int maxUlp)
        {
            if (Precision.Equals(x, y, maxUlp))
            {
                return(0);
            }

            return(x < y
                ? -1
                : 1);
        }
コード例 #3
0
        /// <summary>
        /// Compares two numbers given some amount of allowed distance.
        /// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
        /// </summary>
        /// <param name="x">The first number.</param>
        /// <param name="y">The second number.</param>
        /// <param name="maxUlp">The number of discreet floating point values that are allowed between the two values.</param>
        /// <returns>0 if x equals y, -1 if x is less than y, 1 if x is greater than y.</returns>
        public static int CompareTo(float x, float y, int maxUlp)
        {
            if (Precision.Equals(x, y, maxUlp))
            {
                return(0);
            }

            return(x < y
                ? -1
                : 1);
        }
コード例 #4
0
 /// <summary>
 /// Compares two numbers.
 /// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
 /// </summary>
 /// <param name="x">The first number.</param>
 /// <param name="y">The second number.</param>
 /// <returns><c>true</c> if the two values are equal, otherwise false.</returns>
 /// <remarks>
 /// This will check if the two numbers are adjacent or equal to each other. This is equivalent to
 /// calling Equals(x, y, 1).
 /// </remarks>
 public static bool Equals(double x, double y)
 {
     return(Precision.Equals(x, y, 1));
 }
コード例 #5
0
 /// <summary>
 /// Compares two numbers.
 /// https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
 /// </summary>
 /// <param name="x">The first number.</param>
 /// <param name="y">The second number.</param>
 /// <returns><c>true</c> if the two values are equal, otherwise false.</returns>
 /// <remarks>
 /// This will check if the two numbers are adjacent or equal to each other. This is equivalent to
 /// calling Equals(x, y, 1).
 /// </remarks>
 public static bool Equals(float x, float y)
 {
     return(Precision.Equals(x, y, 1));
 }