RFR: 4511638: Double.toString(double) sometimes produces incorrect results
Raffaello Giulietti
github.com+70726043+rgiulietti at openjdk.java.net
Fri Apr 16 08:09:35 UTC 2021
On Thu, 8 Apr 2021 21:12:21 GMT, Raffaello Giulietti <github.com+70726043+rgiulietti at openjdk.org> wrote:
> Hello,
>
> here's a PR for a patch submitted on March 2020 [1](https://cr.openjdk.java.net/~bpb/4511638/webrev.04/) when Mercurial was a thing.
>
> The patch has been edited to adhere to OpenJDK code conventions about multi-line (block) comments. Nothing in the code proper has changed, except for the addition of redundant but clarifying parentheses in some expressions.
>
>
> Greetings
> Raffaello
Hi Jan,
I had to change a string in test
test/jdk/java/lang/String/concat/ImplicitStringConcatBoundaries.java
because it failed with the current string but passes with the new one. Indeed, the new implementation of Float.toString(float) produces the new string, which, like the current one, is correct in the sense that, upon reading, it recovers Float.MIN_NORMAL.
However, I didn't change the definition of MIN_NORMAL in java.lang.Float because there it is already expressed in hex notation.
As suggested before and by Joe, using the hex representation instead of the decimal would be more robust because the conversions from/to hex are almost trivial, hence much less subject to slight errors. So, rather than printing the raw bits as you suggest, you could use the hex string rendering instead.
Thanks
Raffaello
-------------
PR: https://git.openjdk.java.net/jdk/pull/3402
More information about the core-libs-dev
mailing list