-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Equals
with NaN values (IEEE vs. reflexivity)
#13872
Comments
We can have a discussion about whether we want to change this behavior, but currently there's a couple more points to consider:
|
In my experience This breaks all hash based sets and dictionaries, Code that does actual computations where IEEE semantic is acceptable usually works on concrete types and uses I don't know any precedent in the BCL where
I agree that the behaviour shouldn't depend on the availability of SIMD. My suggestion is to be reflexive in |
@CodesInChaos basically you say that you use equality on I think using A workarounds exists as it is possible to write a |
I apologize for leaving this issue open for so long without giving any closure. For a couple of reasons, we won't be changing this behavior:
|
The built in floating point types compare
NaN
as unequal when using==
and!=
(following IEEE semantics) but compare it as equal when using theEquals
method.Your floating point based types currently use IEEE semantics even for
Equals
. I suggest using the same behaviour as the built in types in your floating point based types like vectors or quaternions.The MSDN documentation of
Equals
contains an exception that allowsA.Equals(A)
to return false on floating point types, so you don't strictly violate its contract.But returning false still breaks hash tables and does not match the behaviour of the built in types, so I consider it a bad idea.
This can be avoided by calling
Equals
on the members instead of==
in the implementation ofEquals
but not in==
and!=
.For example with quaternion,
replace
with
You might want to add tests that check that
==
and!=
compare all the above cases as unequal, so that they match the IEEE specification.Replace:
with:
The text was updated successfully, but these errors were encountered: