Thursday, March 25, 2021

Re: Double equals

In GWT Boolean, Double and String are represented using their unboxed primitive types.

See for Double:
https://github.com/gwtproject/gwt/blob/master/user/super/com/google/gwt/emul/java/lang/Double.java#L130
https://github.com/gwtproject/gwt/blob/master/user/super/com/google/gwt/emul/java/lang/Double.java#L211
https://github.com/gwtproject/gwt/blob/master/dev/core/src/com/google/gwt/dev/jjs/impl/RewriteConstructorCallsForUnboxedTypes.java

So when compiled to JavaScript Double.equals() would be called with primitive types and that's why it can generally do an instance equality check. However Double.NaN is represented using JavaScript NaN (see: https://github.com/gwtproject/gwt/blob/master/user/super/com/google/gwt/emul/java/lang/Double.java#L35 ) and in JavaScript NaN == NaN is always false. 

So I would consider it an emulation bug and equals() needs to check for NaN and handle it correctly with regard to Java behavior. Feel free to create a bug for it on GitHub.

-- J.


blackh...@gmail.com schrieb am Donnerstag, 25. März 2021 um 09:38:28 UTC+1:
Can someone help me with the double.equals
with the following simple code:
      Double value1 = Double.NaN;
      Double value2 = Double.NaN;

      boolean result1 = value1.equals(value2);

In Java result1 = true;
In web with GWt result1 = false;

Looking at the sourcecode i see that the java double has the following equals method:
public boolean equals(Object obj) { 
return (obj instanceof Double) && (doubleToLongBits(((Double)obj).value) == doubleToLongBits(value));
}

the GWT double source code shows the following:
@Override
public boolean equals(Object o) {
return checkNotNull(this) == o;
}

I do not really understand the GWT version. th emost important thing is that the equals has different results between java and GWT.
How to resolve this?

Regards,

Jasper

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit/033df899-31e5-42f0-9e00-7ed1474d5313n%40googlegroups.com.

1 comment:

  1. Packers and Movers Hyderabad Give Certified and Verified Service Providers, Cheap and Best ###Office Relocation Charges, ***Home Shifting, ✔✔✔Goods Insurance worth Rs. 10,000, Assurance for Local and Domestic House Shifting. Safe and Reliable Household Shifting Services in Hyderabad with Reasonable Packers and Movers Price Quotation @ Packers And Movers Hyderabad

    ReplyDelete