Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/13/19 14:50:26 (4 years ago)
Author:
chaider
Message:

#3032

  • Added IsAlmost method with an epsilon parameter
  • Added check for floating point issues at interval constructor
  • Updated absolute operator (jump over zero between lower and upper bound)
  • Updated analytical quotient to use already implemented operators to build it
  • Updated test cases for operators
  • Refactored test method names
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Common/3.3/DoubleExtensions.cs

    r17180 r17350  
    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></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></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.