diff --git a/Compare-NET-Objects-Tests/BugTests.cs b/Compare-NET-Objects-Tests/BugTests.cs index 1d4d167..0d26201 100644 --- a/Compare-NET-Objects-Tests/BugTests.cs +++ b/Compare-NET-Objects-Tests/BugTests.cs @@ -52,6 +52,18 @@ public void Cleanup() #region Tests + [Test] + public void PositiveInfinityShouldBeTheSame() + { + double positiveInfinity = Double.PositiveInfinity; + double positiveInfinity2 = Double.PositiveInfinity; + + CompareLogic compareLogic = new CompareLogic(); + var result = compareLogic.Compare(positiveInfinity, positiveInfinity2); + Console.WriteLine(result.DifferencesString); + Assert.IsTrue(result.AreEqual); + } + [Test] public void PositiveInfinityAndNegativeInfinityShouldBeDifferent() { diff --git a/Compare-NET-Objects/TypeComparers/DoubleComparer.cs b/Compare-NET-Objects/TypeComparers/DoubleComparer.cs index 13ab45a..951003d 100644 --- a/Compare-NET-Objects/TypeComparers/DoubleComparer.cs +++ b/Compare-NET-Objects/TypeComparers/DoubleComparer.cs @@ -39,6 +39,12 @@ public override void CompareType(CompareParms parms) Double double1 = (Double)parms.Object1; Double double2 = (Double)parms.Object2; + if (Double.IsPositiveInfinity(double1) && Double.IsPositiveInfinity(double2)) + return; + + if (Double.IsNegativeInfinity(double1) && Double.IsNegativeInfinity(double2)) + return; + double diff = double1 - double2; if ((Math.Abs(diff) > parms.Config.DoublePrecision) || (Double.IsNaN(diff) && (!Double.IsNaN(double1) || !Double.IsNaN(double2))))