-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[release/5.0] Fix half equality method #41296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
| } | ||
|
|
||
| /// <summary>Determines whether the specified value is finite (zero, subnormal, or normal).</summary> | ||
|
|
@@ -415,14 +422,11 @@ public override bool Equals(object? obj) | |
| /// </summary> | ||
| public bool Equals(Half other) | ||
| { | ||
| if (IsNaN(this) || IsNaN(other)) | ||
| if (this == other) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the implementation slower than it needs to be - the I think it would be better to inline the logic here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just copied the implementation from
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it is ok to merge this change as is into release/5.0. I have opened #41329 on the optimization. |
||
| { | ||
| // 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); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.