diff --git a/src/libraries/System.Private.CoreLib/src/System/Half.cs b/src/libraries/System.Private.CoreLib/src/System/Half.cs
index 34adab5856cb67..1840f3c61107e6 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Half.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Half.cs
@@ -57,7 +57,7 @@ namespace System
// Well-defined and commonly used values
- public static Half Epsilon => new Half(EpsilonBits); // 5.9604645E-08
+ public static Half Epsilon => new Half(EpsilonBits); // 5.9604645E-08
public static Half PositiveInfinity => new Half(PositiveInfinityBits); // 1.0 / 0.0;
@@ -151,12 +151,19 @@ private ushort Significand
public static bool operator ==(Half left, Half right)
{
- return left.Equals(right);
+ if (IsNaN(left) || IsNaN(right))
+ {
+ // IEEE defines that NaN is not equal to anything, including itself.
+ return false;
+ }
+
+ // IEEE defines that positive and negative zero are equivalent.
+ return (left._value == right._value) || AreZero(left, right);
}
public static bool operator !=(Half left, Half right)
{
- return !(left.Equals(right));
+ return !(left == right);
}
/// Determines whether the specified value is finite (zero, subnormal, or normal).
@@ -415,14 +422,11 @@ public override bool Equals(object? obj)
///
public bool Equals(Half other)
{
- if (IsNaN(this) || IsNaN(other))
+ if (this == other)
{
- // IEEE defines that NaN is not equal to anything, including itself.
- return false;
+ return true;
}
-
- // IEEE defines that positive and negative zero are equivalent.
- return (_value == other._value) || AreZero(this, other);
+ return IsNaN(this) && IsNaN(other);
}
///
diff --git a/src/libraries/System.Runtime/tests/System/HalfTests.cs b/src/libraries/System.Runtime/tests/System/HalfTests.cs
index de5eddf9f9dc79..69dd6310959fb1 100644
--- a/src/libraries/System.Runtime/tests/System/HalfTests.cs
+++ b/src/libraries/System.Runtime/tests/System/HalfTests.cs
@@ -335,7 +335,7 @@ public static IEnumerable