godot icon indicating copy to clipboard operation
godot copied to clipboard

Do not consider NaNs equal in float values derived from Variant

Open puchik opened this issue 1 year ago • 4 comments

Hash scalar compare for Variants which are floats no longer considers two NaN values as equal.

Closes #72222

puchik avatar Mar 08 '23 03:03 puchik

CC @hpvb who introduced this code back in 2017 with #7815 (+ #8393).

The behavior for Dictionary with NAN keys was then later changed with #16114 to fix #16031. Would this PR reintroduce that bug?

akien-mga avatar Mar 08 '23 08:03 akien-mga

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

AThousandShips avatar Mar 08 '23 08:03 AThousandShips

Maybe we should add a hash compare that treats NaN as equal and use it for dictionary, where we technically care about binary equality

AThousandShips avatar Mar 08 '23 08:03 AThousandShips

I believe this will reintroduce the bug as it is.

vnen avatar Mar 08 '23 15:03 vnen

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.

image

puchik avatar Mar 11 '23 20:03 puchik

PS: In the future, when posting a screenshot of code, please include it in Markdown as well between triple backticks (and the gdscript syntax highlighting language) so that other people can test it easily. (This is also more accessible to screen readers.)

Calinou avatar Jun 22 '23 21:06 Calinou

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.

reduz avatar Aug 18 '23 07:08 reduz

I'm not sure if the memory error is a problem with the workflow. Especially because all I changed was the order of the if conditions and it seems to be connected to Vulkan, plus I'm not able to reproduce it.

puchik avatar Sep 01 '23 00:09 puchik

That's a race condition unrelated to this PR, it happens every now and then. I restarted the build.

akien-mga avatar Sep 01 '23 06:09 akien-mga

I see. Thanks!

puchik avatar Sep 01 '23 07:09 puchik

Thanks!

akien-mga avatar Sep 27 '23 12:09 akien-mga