-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Support numeric/binary hash comparison for floats derived from Variants (as well as existing semantic comparison) #74588
Support numeric/binary hash comparison for floats derived from Variants (as well as existing semantic comparison) #74588
Conversation
Because of macros I would keep the parentheses around the values, just to be safe For example: hash_compare_scalar(a&b,c) would break, not that it's likely to happen but macros are confusing |
Maybe we should add a hash compare that treats NaN as equal and use it for dictionary, where we technically care about binary equality |
I believe this will reintroduce the bug as it is. |
deab627
to
759f05b
Compare
Looks like this was quite a controversial series of bugs and decisions 🙂 It does look like to support both the best way I can think of is two functions. I pushed a change that addresses this with I think the least code duplication as possible and doesn't break compatibility. I tested with the original target issue (#72222) and previous issues (#16114, #7354, #6947, #8081, #16031) and all cases seem covered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally (rebased on top of master
b0c3c00), it works as expected.
PR output
1
=======================
false
false
=======================
(-3, 2)
=======================
master
output
1
=======================
false
true
=======================
(-3, 2)
=======================
Code
extends Node
func _ready():
var d = {}
d[Vector2(NAN, NAN)] = 0
d[Vector2(NAN, NAN)] = 0
print(d.size())
print("=======================")
var foo = { foo = NAN }
var bar = { foo = NAN }
print(foo.foo == bar.foo) # false
print(foo == bar) # true
print("=======================")
Vector2(3, -2)
print(Vector2(-3, 2))
print("=======================")
var x = 200 * cos(2 * PI / (0))
var y = 200 * sin(2 * PI / (0))
PS: In the future, when posting a screenshot of code, please include it in Markdown as well between triple backticks (and the |
759f05b
to
c9356f3
Compare
This makes sense to me, but hard to know if it will break something. Probably better to give it a go and be very attentive to see what happens. |
Hash comparison for Variant continues to perform semantic/logical comparison with NaN's considered equal by default (to prevent godotengine#16114, godotengine#7354, godotengine#6947, godotengine#8081), but now optionally allows for numeric comparison that does not consider NaN's equal to support proper value comparison (for godotengine#72222)
c9356f3
to
ee27254
Compare
I'm not sure if the memory error is a problem with the workflow. Especially because all I changed was the order of the |
That's a race condition unrelated to this PR, it happens every now and then. I restarted the build. |
I see. Thanks! |
Thanks! |
Hash scalar compare for Variants which are floats no longer considers two NaN values as equal.Hash comparison for Variant continues to perform semantic/logical comparison with NaN's considered equal by default (to prevent #16114, #7354, #6947, #8081, #16031), but now optionally allows for numeric comparison that does not consider NaN's equal to support proper value comparison (for #72222)
semantic_comparison
argument to existinghash_compare
implementation(s) that is set to true by default.hash_comparison_base
macro to support existinghash_compare
values with default semantic comparison.Closes #72222