Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/06/20 17:41:28 (4 years ago)
Author:
mkommend
Message:

#3032: Merged r17301, r17302, r17305, r17306, r17348, r17350, r17351 into stable.

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Common/3.3/DoubleExtensions.cs

    r17181 r17495  
    2323namespace HeuristicLab.Common {
    2424  public static class DoubleExtensions {
     25    /// <summary>
     26    /// Compares the similarity of value x and value y with a precision of 1.0E-12.
     27    /// </summary>
     28    /// <param name="x">First double value to be checked</param>
     29    /// <param name="y">Second double value to compare with</param>
     30    /// <returns>true if the difference is <= 1.0E-12</returns>
    2531    public static bool IsAlmost(this double x, double y) {
     32      var epsilon = 1.0E-12;
     33      return IsAlmost(x, y, epsilon);
     34    }
     35
     36    /// <summary>
     37    /// Compares the similarity of value x and value y with a given precision (epsilon).
     38    /// </summary>
     39    /// <param name="x">First double value to be checked</param>
     40    /// <param name="y">Second double value to compare with</param>
     41    /// <param name="epsilon">Error term to specify the precision</param>
     42    /// <returns>true if the difference is <= epsilon</returns>
     43    public static bool IsAlmost(this double x, double y, double epsilon) {
    2644      if (double.IsInfinity(x)) {
    2745        if (x > 0) return double.IsPositiveInfinity(y);
    2846        else return double.IsNegativeInfinity(y);
    2947      } else {
    30         return Math.Abs(x - y) < 1.0E-12;
     48        return Math.Abs(x - y) < epsilon;
    3149      }
    3250    }
Note: See TracChangeset for help on using the changeset viewer.