Saturday, April 26, 2025

Re: IEEE 754 mode for Java

You are correct, not really a GWT question.  Apologies.  Just a by product of using GWT.

> Can you give an example of the computation you're doing

This is my problem at the moment.  I haven't been able to replicate it in a simple example.  Trying something like:

double test = 12345678d;
for (int i = 1; i < 1_000_000; i++) {
  if (i % 2 == 0) {
    test = test * (double)i;
  } else {
    test = test / (double)i;
  }
}
Gives 15473.01664039943 in all cases.  In my real world test, there are thousands of lines of code.

> Also is there any chance that your tests are recognized by the compiler to be operations on constants, so the work is all being done at compile time rather than letting the browser actually do any work?

Obsolutely there is.  I asked AI about my problem, and it told me it was due to Java not following the IEEE 754 standard and I have to expect inconsistant results.  However, I don't know if that's correct.  There are people saying Java does follow IEEE 754 and others that say it doesn't.

> Which browsers do you test with - does HtmlUnit pass these as well?

I've checked Chrome, Edge, and Firefox.  All give the same result.  I haven't tried HtmlUnit yet (I'll implement some GWTTestCase's now).

On Sunday, 27 April 2025 at 9:44:32 am UTC+10 Colin Alworth wrote:
(Sounds like this isn't actually a gwt question at all, but a java one, since gwt apparently is "right" where Java is wrong?)

Can you give an example of the computation you're doing - like a series of multiply/add/etc operations, or using Math/StrictMath and friends?

Also is there any chance that your tests are recognized by the compiler to be operations on constants, so the work is all being done at compile time rather than letting the browser actually do any work?

Which browsers do you test with - does HtmlUnit pass these as well?

-- 
  Colin Alworth


On Sat, Apr 26, 2025, at 6:24 PM, Craig Mitchell wrote:
I have some code that does millions of chained multiplications and divisions with doubles.

When I compile the code with GWT to Javascript, I get consistent results, no matter what the browser.  I believe this is because Javascript follows the IEEE 754 standard.

However, running the same code in Java does not get consistent results.  Not only are the results different from Javascript, they are different based on how I run the tests.  Ie: Running from IntelliJ's JUnit runner vs running with "mvn test" gives different results.

I would like the results from Java to match the results from JavaScript (follow the IEEE 754 standard).

I'm on Windows, running Java Temurin 21.0.5 64-Bit.

Has anyone else faced this problem?  Any ideas for a solution?


--
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-tool...@googlegroups.com.

--
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 visit https://groups.google.com/d/msgid/google-web-toolkit/e21d0e41-c297-4cf6-b1e2-6cc00f171b49n%40googlegroups.com.

No comments:

Post a Comment