Changeset 5739


Ignore:
Timestamp:
03/17/11 16:30:37 (11 years ago)
Author:
gkronber
Message:

#1443 minor change to reduce expected number of comparisons in double.IsAlmost extension

File:
1 edited

Legend:

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

    r5705 r5739  
    2424  public static class DoubleExtensions {
    2525    public static bool IsAlmost(this double x, double y) {
    26       if (double.IsPositiveInfinity(x)) return double.IsPositiveInfinity(y);
    27       if (double.IsNegativeInfinity(x)) return double.IsNegativeInfinity(y);
    28 
    29       return Math.Abs(x - y) < 1.0E-12;
     26      if (double.IsInfinity(x)) {
     27        if (x > 0) return double.IsPositiveInfinity(y);
     28        else return double.IsNegativeInfinity(y);
     29      } else {
     30        return Math.Abs(x - y) < 1.0E-12;
     31      }
    3032    }
    3133  }
Note: See TracChangeset for help on using the changeset viewer.