On Fri, Jul 11, 2025 at 11:44 AM fabioromano1 <d...@openjdk.org> wrote: > > On Fri, 11 Jul 2025 18:07:31 GMT, fabioromano1 <d...@openjdk.org> wrote: > > >> This PR implements nth root computation for BigIntegers using Newton method. > > > > fabioromano1 has updated the pull request incrementally with one additional commit since the last revision: > > > > Avoid to discard fraction bits in the initial estimate > > The current explanation for the exception of negative `n` is justified by consistency with the explanation for negative `exponent` in `BigInteger.pow(int)`, so changing this explanation would cause an inconsistency in the documentation of `BigInteger` operations. > But the mathematics are completely different. The comment makes sense for pow(), which naturally produces integers for non-negative arguments.
It makes no sense at all for nthRoot, which almost never naturally produces an integer. We make it produce an integer via suitable truncation, as the spec says. We could clearly do the same thing for negative n, though I tend to agree we probably don't want to. Let's please not fake consistency here where there inherently is none. the integers are closed under positive powers, and not under positive nthRoots. We can't change that. Hans