RFR: 8341470: BigDecimal.stripTrailingZeros() optimization [v32]

Raffaello Giulietti rgiulietti at openjdk.org
Wed Oct 9 14:50:05 UTC 2024


On Mon, 7 Oct 2024 19:35:10 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> An optimized algorithm for `BigDecimal.stripTrailingZeros()` that uses repeated squares trick.
>
> fabioromano1 has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Use log cache of BigInteger

Small changes.

src/java.base/share/classes/java/math/BigInteger.java line 1299:

> 1297: 
> 1298:     /** The cache of logarithms of radices for base conversion. */
> 1299:     static final double[] logCache;

I'd prefer this to remain `private`.

It's not a big deal to have `private static final double LOG_5_OF_2 = Math.log(2) / Math.log(5)` in `BigDecimal`.

src/java.base/share/classes/java/math/BigInteger.java line 1302:

> 1300: 
> 1301:     /** The natural log of 2.  This is used in computing cache indices. */
> 1302:     static final double LOG_TWO = Math.log(2.0);

Same here, please revert to `private`.

-------------

PR Review: https://git.openjdk.org/jdk/pull/21323#pullrequestreview-2357388419
PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1793666210
PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1793666261


More information about the core-libs-dev mailing list