RFR: 8341470: BigDecimal.stripTrailingZeros() optimization [v32]
fabioromano1
duke at openjdk.org
Wed Oct 9 12:27:00 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
src/java.base/share/classes/java/math/BigDecimal.java line 5268:
> 5266: intVal = intVal.shiftRight(powsOf2); // remove powers of 2
> 5267: // maxPowsOf5 == ceil(log5(intVal)) roughly
> 5268: long maxPowsOf5 = (long) Math.ceil(intVal.bitLength() * BigInteger.LOG_TWO / BigInteger.logCache[5]);
@rgiulietti Can make sense using `Math.round()` instead of `Math.ceil()` to get better upper bound?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21323#discussion_r1793425020
More information about the core-libs-dev
mailing list