RFR: 8356709: Avoid redundant String formatting in BigDecimal.valueOf(double)
Johannes Graham
duke at openjdk.org
Mon May 12 14:43:12 UTC 2025
On Sun, 11 May 2025 18:45:47 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Optimize `BigDecimal.valueOf(double)` by using `FormattedFPDecimal` instead of converting to decimal string and then parsing it. This results in an approximate 6x improvement for me.
>
> test/jdk/java/math/BigDecimal/ValueOfDouble.java line 14:
>
>> 12:
>> 13: public class ValueOfDouble {
>> 14: private static final String DIGITS = "1234567899123456789"; // Enough digits to fill a long
>
> Should we consider including 0 in this list?
>
> This file needs a license header, and the jtreg directive should be `/*` instead of `/**` and usually placed before imports, and usually we include a `@bug` tag (once there is an issue ID) and a `@summary` tag.
I left out 0 specifically to ensure the all precisions were tried. The loop over the exponents effectively adds zeros afterwards.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25173#discussion_r2083600670
More information about the core-libs-dev
mailing list