On Sun, 11 May 2025 16:22:11 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 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)` ------------- PR Comment: https://git.openjdk.org/jdk/pull/25173#issuecomment-2869969120 PR Review Comment: https://git.openjdk.org/jdk/pull/25173#discussion_r2083568201