On Tue, 22 Jul 2025 15:26:25 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> 
wrote:

>> 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.

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

The cases in which the method throws correspond to the cases in which the 
integer root is not defined.

> 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.

By "the real n-th root of x" is meant the usual definition of "principal nth 
root", namely the only solution of $y^n = x$ for $y \in (-\infty; + \infty)$ 
that is concordant with the signum of $x$, if it exists. For the specification, 
the equivalence of the definition with the formula $\mathrm{signum}(x) \cdot 
\lfloor|\sqrt[n]{x}| \rfloor$ makes sense only when the definition itself makes 
sense, i.e. only when the method does not throw.

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

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

Reply via email to