RFR: 8366478: BigDecimal roots [v4]

Raffaello Giulietti rgiulietti at openjdk.org
Fri Oct 17 11:34:22 UTC 2025


On Thu, 16 Oct 2025 19:36:46 GMT, fabioromano1 <duke at openjdk.org> wrote:

>> src/java.base/share/classes/java/math/BigDecimal.java line 2181:
>> 
>>> 2179:      * @param mc the context to use.
>>> 2180:      * @return the {@code n}<sup>th</sup> root of {@code this}.
>>> 2181:      * @throws ArithmeticException if {@code n == 0 || n == Integer.MIN_VALUE}.
>> 
>> Just out of curiosity, is there a technical reason for the restriction on MIN_VALUE?
>
> Yes, `|Integer.MIN_VALUE|` is out of range of `int`s, so it cannot be used as a degree for `BigInteger.nthRoot(int)`.

I'm not sure I get your point: how come is`MIN_VALUE` out of `int` range?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27148#discussion_r2439488233


More information about the core-libs-dev mailing list