On Sun, 11 May 2025 16:32:02 GMT, Johannes Graham <d...@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. > > On Aarch64 M4: > > Benchmark Mode Cnt Score Error Units > + BigDecimals.testValueOfWithDouble avgt 15 9.913 ± 0.080 ns/op > - BigDecimals.testValueOfWithDoubleString avgt 15 65.846 ± 0.801 ns/op @j3graham This seems like a nice improvement. I'll take a deeper look in some days from now. @j3graham Since @liach created the JBS issue, you should change the PR title to match the title of the issue. > src/java.base/share/classes/java/math/BigDecimal.java line 1398: > >> 1396: public static BigDecimal valueOf(double val) { >> 1397: if (!Double.isFinite(val)) { >> 1398: throw new NumberFormatException("Infinite or NaN"); > > Note, this changes the exception message. The new message is consistent with > `new BigDecimal(double)` Yeas, we usually only rely on the exception type, not on the specific message, which is not part of the method spec. While it is nice to keep the message unchanged over releases, it is sometimes hard to do so consistently. ------------- PR Comment: https://git.openjdk.org/jdk/pull/25173#issuecomment-2872414863 PR Comment: https://git.openjdk.org/jdk/pull/25173#issuecomment-2872438246 PR Review Comment: https://git.openjdk.org/jdk/pull/25173#discussion_r2084598684