Test if Double is greater than some other value by some degree of error in epsilon. - CSharp System

CSharp examples for System:Math Number

Description

Test if Double is greater than some other value by some degree of error in epsilon.

Demo Code

/// A port of the LoDMath static member class written in AS3 under the MIT license agreement.
using System.Linq;
using System.Collections.Generic;
using System;/*from w  w w  .  ja  v  a  2  s.co  m*/

public class Main{
        public static bool FuzzyLessThan(double a, double b)
        {
            return FuzzyLessThan(a, b, EPSILON);
        }
        /// <summary>
        /// Test if Double is greater than some other value by some degree of error in epsilon.
        /// 
        /// Due to float error, two values may be considered similar... but the computer considers them different. 
        /// By using some epsilon (degree of error) once can test if the two values are similar.
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="epsilon"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool FuzzyLessThan(double a, double b, double epsilon)
        {
            return a < b + epsilon;
        }
}

Related Tutorials