diff --git a/SignificantNumber.Test/SignificantNumberValueTypeTests.cs b/SignificantNumber.Test/SignificantNumberValueTypeTests.cs
index c4a6b00..d0fd34e 100644
--- a/SignificantNumber.Test/SignificantNumberValueTypeTests.cs
+++ b/SignificantNumber.Test/SignificantNumberValueTypeTests.cs
@@ -295,4 +295,34 @@ public void CompareAtSignificance_ComparesAtTheLowerSignificantDigitCount(string
{
Assert.AreEqual(expected, int.Sign(SignificantNumber.CompareAtSignificance(Parse(left), Parse(right))));
}
+
+ [TestMethod]
+ [DataRow("1.5", "1.5", true)]
+ [DataRow("1.50", "1.5", true)]
+ [DataRow("0", "0", true)]
+ [DataRow("-2.25", "-2.25", true)]
+ [DataRow("1.5", "1.4", false)]
+ [DataRow("1.4", "1.5", false)]
+ public void EqualsPreciseNumber_AgreesInBothArgumentOrdersAndWithOperator(string significant, string precise, bool expected)
+ {
+ SignificantNumber s = Parse(significant);
+ PreciseNumber p = PreciseNumber.Parse(precise, CultureInfo.InvariantCulture);
+
+ Assert.AreEqual(expected, s == p, $"{s} == {p}");
+ Assert.AreEqual(expected, s.Equals(p), $"{s}.Equals({p})");
+ Assert.AreEqual(expected, p.Equals(s), $"{p}.Equals({s})");
+ Assert.AreEqual(expected, s.CompareTo((object)p) == 0, $"{s}.CompareTo((object){p}) == 0");
+ }
+
+ [TestMethod]
+ public void EqualsObject_BoxedPreciseNumber_IsFalseEvenWhenEqual()
+ {
+ SignificantNumber s = Parse("1.5");
+ object boxed = PreciseNumber.Parse("1.5", CultureInfo.InvariantCulture);
+
+ // The record struct's Equals(object) only accepts another SignificantNumber, so a boxed PreciseNumber is
+ // never equal to it, although CompareTo(object) treats the two as the same value.
+ Assert.IsFalse(s.Equals(boxed));
+ Assert.AreEqual(0, s.CompareTo(boxed));
+ }
}
diff --git a/SignificantNumber/SignificantNumber.cs b/SignificantNumber/SignificantNumber.cs
index 9179e20..a2005ea 100644
--- a/SignificantNumber/SignificantNumber.cs
+++ b/SignificantNumber/SignificantNumber.cs
@@ -891,6 +891,21 @@ obj is SignificantNumber significantNumber
? Value.CompareTo(significantNumber.Value)
: Value.CompareTo(obj);
+ ///
+ /// Determines whether the current instance holds the same value as a .
+ ///
+ /// The precise number to compare with the current instance.
+ /// if the values are equal; otherwise, .
+ ///
+ /// The values are compared exactly, so the result agrees with == and with
+ /// called the other way round. A boxed as
+ /// an still goes to through the record's
+ /// Equals(object), which returns because the object is not a
+ /// , even though returns zero for it.
+ ///
+ public bool Equals(PreciseNumber other) =>
+ Value.Equals(other);
+
///
/// Returns the absolute value of the specified .
///