Changeset 17409 for branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Common/3.3/DoubleExtensions.cs
- Timestamp:
- 01/28/20 12:14:21 (5 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Common/3.3/DoubleExtensions.cs
r17246 r17409 23 23 namespace HeuristicLab.Common { 24 24 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> 25 31 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) { 26 44 if (double.IsInfinity(x)) { 27 45 if (x > 0) return double.IsPositiveInfinity(y); 28 46 else return double.IsNegativeInfinity(y); 29 47 } else { 30 return Math.Abs(x - y) < 1.0E-12;48 return Math.Abs(x - y) < epsilon; 31 49 } 32 50 }
Note: See TracChangeset
for help on using the changeset viewer.