On Wed, 16 Jul 2025 14:40:53 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> 
wrote:

>> I don't know other ways to define it that don't involve the clause `!(x < 0 
>> && n % 2 == 0)`. If the first definition is confusing, the only solution I 
>> see is to remove it, and leave only the formula `(x.signum() * 
>> floor(abs(nthRoot(x, n))))`.
>
> I think this is probably what you are searching for.
> 
> If x ≥ 0 there's at most one integer y ≥ 0 meeting y^n ≤ x < (y+1)^n.
> If x < 0 there's at most one integer y ≤ 0 meeting y^n ≥ x > (y-1)^n.
> The method returns y if it exists, and throws otherwise.
> As a consequence, it throws when n ≤ 0, or when x < 0 and n is even, and 
> returns a result otherwise.
> 
> Can you please check?

The new definition leaves some questions open.

When the largest or smallest integer does not exist, nothing is stated.

What is meant here with "the real n-th root of x"? If it is a solution of y^n = 
x, then for n = x = -1 it is y = -1, so this method would need to return -1, 
but it throws.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24898#discussion_r2222934458

Reply via email to