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

fabioromano1 duke at openjdk.org
Thu Oct 10 20:28:13 UTC 2024


On Thu, 10 Oct 2024 19:44:21 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/math/BigDecimal.java line 5270:
>> 
>>> 5268:         intVal = intVal.shiftRight(powsOf2); // remove powers of 2
>>> 5269:         // maxPowsOf5 == ceil(log5(intVal)) roughly
>>> 5270:         long maxPowsOf5 = (long) Math.ceil(intVal.bitLength() * LOG_5_OF_2);
>> 
>> Please document the meaning of this variable in form of inequalities w.r.t. `intVal`.
>> Also, shouldn't it be named `maxExpOf5` or similar? It's an exponent, after all.
>
> The name `maxPowsOf5` has been chosen for consistence with `powsOf2`.

Could 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_r1796053786


More information about the core-libs-dev mailing list