-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
System.Numerics.Vector2.Equals doesn't use float.Equals in Equals implementation #58853
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsIt is possible to add multiple While it isn't possible to add multiple
|
@tfenise thank you, I'm sorry I didn't search properly enough. I read the discussion and it seems most likely this issue won't be addressed. I agree with @CodesInChaos I also want to point to what MSDN says Object.Equals Method:
Indeed instances of Removing So I suggest one of two following things:
My case. I was iterating over properties of some data recursively with reflection. The idea was 1. find values of types for which validators are defined and validate them 2. test getters. There's a Vector2 implementation in our game engine and I quickly stumbled upon a case of vector instance properties returning other Vector2 instances resulting in infinite recursion and stack overflow. I thought I can mitigate that by storing all processed instances in I understand this approach is not very good and something like Vector2 property |
I have a different opinion on this than Eric did and am willing to consider the breaking change here. It is unexpected that vmovupd xmm0, [rdx] ; load left into xmm0
vmovupd xmm1, [r8] ; load right into xmm1
vcmpeqps xmm2, xmm0, xmm1 ; get mask of left == right following IEEE 754 rules
+ vcmpunordps xmm0, xmm0, xmm0 ; get mask of NaN values in left
+ vcmpunordps xmm1, xmm1, xmm1 ; get mask of NaN values in right
+ vandps xmm0, xmm0, xmm1 ; get mask of NaN values in left & right
+ vorps xmm0, xmm0, xmm2 ; combine mask of IEEE equality with mask of NaN values in left & right
vmovmskps eax, xmm0 ; extract upper bit of each element from mask to integer register
cmp eax, 0xf ; compare to see if all entries are "true"
sete al ; normalize to 1 or 0
movzx eax, al ; zero extend result This is notably 4 instructions more expensive than the current implementation and is a breaking change from current behavior. However, it would only impact users relying on |
Marking this as
My own take on 1 is that this is largely no different from a Having an analyzer is potentially a decent alternative to help catch incorrect usages of this. |
Concerning efficient implementation: Discussion on stackoverflow |
I don't think the analyzer will help in case of adding objects to a |
It likely wouldn't no. Analyzers will never catch all cases, but they can certainly help catch common cases and pitfalls, which is the general goal. I think fixing it is likely the better option, but there are several factors to consider and we may choose a different path ultimately. |
|
@terrajobst, I think you mean .NET 7. It's likely too late to take this for .NET 6 😄 |
That would be great! |
@tannergooding should tihs be 'up for grabs' (possibly for @rotanov if he's interested)? |
@danmoseley, this one likely requires JIT work. If someone feels confident enough in C# and C++ to do both sides of the work, then I'm happy to assign it out. But it's not necessarily an "easy" issue. |
"up-for-grabs" doesn't imply easy, we've had community members handle that kind of task before I think. But it maybe nobody "grabs" it... |
It is possible to add multiple
new System.Numerics.Vector2(float.NaN, float.NaN)
to aHashSet<object>
:While it isn't possible to add multiple
float.NaN
becausefloat.NaN == float.NaN
is falsefloat.NaN.Equals(float.NaN)
is trueThis applies to other System.Numeric.* structures as well.
The text was updated successfully, but these errors were encountered: