Questions about Float.toString(float)
LP
lp.coolbeans at proton.me
Sun Jun 5 07:59:59 UTC 2022
Hi,
(1)
float f = Float.intBitsToFloat(260046848);
JDK 17: Float.toString(f) -> 1.26217745E-29
master: Float.toString(f) -> 1.2621775E-29
BigDecimal.valueOf(Float.intBitsToFloat(260046847)) -> 1.2621773731219804E-29
BigDecimal.valueOf(Float.intBitsToFloat(260046848)) -> 1.2621774483536189E-29
BigDecimal.valueOf(Float.intBitsToFloat(260046849)) -> 1.2621775988168958E-29
What about 1.2621774E-29? I believe both 1.2621774E-29 and 1.2621775E-29 satisfy the Javadoc of Float.toString(float), so maybe it doesn't matter, but 1.2621774E-29 is closer to f.
(2)
float f = Float.intBitsToFloat(1291845637);
JDK 17: Float.toString(f) -> 1.34217808E8
master: Float.toString(f) -> 1.3421781E8
BigDecimal.valueOf(Float.intBitsToFloat(1291845636)) -> 134217792
BigDecimal.valueOf(Float.intBitsToFloat(1291845637)) -> 134217808
BigDecimal.valueOf(Float.intBitsToFloat(1291845638)) -> 134217824
What about 1.342178E8? 1.3421781E8 is an improvement over 1.34217808E8, but it's still not conforming to the Javadoc if 1.342178E8 is valid.
Apologies if I misunderstood something.
Thanks,
LP
More information about the core-libs-dev
mailing list