-
Notifications
You must be signed in to change notification settings - Fork 18k
reflect: Value.IsZero should report true for negative zero #61827
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
Comments
Whoops, I looked at the |
Noting here: @ianlancetaylor says in #61372 (comment):
|
In the example:
I think these should all report true. Is that what everyone else thinks too? |
Change https://go.dev/cl/517777 mentions this issue: |
This proposal has been added to the active column of the proposals project |
Based on the discussion above, this proposal seems like a likely accept. |
I might be misunderstanding how generic functions are compiled, but does this mean that the compiler has to track which type arguments are floats so that it can compile the Or... what is this supposed to print, once |
The compiler already has to use floating-point equality semantics for any use of |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/524615 mentions this issue: |
I discovered this while exploring #61372 (comment).
In that comment, I asked whether
v == zero
is identical toreflect.ValueOf(&v).Elem().IsZero()
.And the answer is unfortunately, "no":
The fact that
negStructZero
andnegArrayZero
report true is due to a regression I accidentally introduced in CL/411478 and has been live since Go 1.20.Looking through #7501, there was no discussion how -0 is handled.
In CL/171337, @dsnet and @bradfitz called out how -0 should be handled, but I don't think there was a principled way to think through how it should actually be handled.
We are currently in a state where we are inconsistent.
I propose we make
v == zero
identical toreflect.ValueOf(&v).Elem().IsZero()
,which means that
reflect.ValueOf(negZero).IsZero()
should report true.\cc @ianlancetaylor @rsc @bradfitz
The text was updated successfully, but these errors were encountered: