Skip to content

Correctly support Double/Float equals semantics - #10431

Open
niloc132 wants to merge 14 commits into
gwtproject:mainfrom
niloc132:9568-double-equals-with-object.is-test
Open

niloc132 wants to merge 14 commits into
gwtproject:mainfrom
niloc132:9568-double-equals-with-object.is-test

Conversation

@niloc132

@niloc132 niloc132 commented Nov 5, 2026

Copy link
Copy Markdown
Member

Previously, boxed positive/negative zeroes and NaN values had the same equality semantics as primitives, which is incorrect for boxed Double/Float values in Java.

Among other things, this now allows boxed Double/Float values to be correctly found in collections via Object.equals() calls.

This also modifies how Java == is handled for Double instances - arguably this is still "wrong", in the same way that it is wrong for String to be compared via == and be true, but it happens to reflect the new reality that JEP 401 will bring.

By itself, this cases a small size regression, as a method call is larger than ===, but nearly all of the JS === compares are wrapped with maskUndefined, so we could fold that in for these specific cases, since we must have a method call anyway. Doing so brings this change from about +0.1% increase to -0.01% decrease.

BoxedDoubleIdentityTest was generated by an LLM based on the range of valid Java comparisons and their JS counterparts, the rest was written by hand.

Js's Object.is() would be a more concise fix for this, but has subtle int/float bugs until HtmlUnit 5.6, we can consider a slightly smaller approach once we update that far.

Fixes #9568

niloc132 and others added 14 commits October 31, 2026 07:13
Previously, boxed positive/negative zeroes and NaN values had the same
equality semantics as primitives, which is incorrect for Java.

Among other things, this now allows boxed Doubles to be correctly found
in collections via Object.equals() calls.

Fixes gwtproject#9568
This reverts commit b6d3d50.

The optimizer can rewrite Object/Object comparisons to Double/String and
the like, which violates these assumptions. Arguably, we should instead
statically evaluate those comparisons to false, but cases where the
optimization loop ends early could still leave these intact.
@niloc132 niloc132 added this to the 2.14 milestone Nov 5, 2026
@zbynek zbynek added the ready This PR has been reviewed by a maintainer and is ready for a CI run. label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready This PR has been reviewed by a maintainer and is ready for a CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emulated indexOf() is incorrect compared to jdk indexOf()

2 participants