RFR: 8077587: BigInteger Roots [v52]

Raffaello Giulietti rgiulietti at openjdk.org
Mon Jul 28 17:08:04 UTC 2025


On Mon, 28 Jul 2025 14:03:16 GMT, fabioromano1 <duke at 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:
> 
>   Zimmermann suggestion

src/java.base/share/classes/java/math/MutableBigInteger.java line 1993:

> 1991:              * non-significant bits), and the shift is performed in order to lose
> 1992:              * the smallest number of bits in the significand if necessary (minimizing loss of precision).
> 1993:              */

@fabioromano1 I've now spent several hours trying to "reverse engineer" (Java code -> maths) what is going on in the code below that tries to come up with a nice initial estimate of the end result, before starting Newton's loop.
I'm still not 100% sure I've got everything correctly, and whether each detail is mathematically sound.
The same will probably happen to other readers and maintainers in the future.

I understand the overall tactic described in the comment above. However, the details of the different (sub)cases deserve (and need) a more detailed documentation to help and guide future enhancements and fixes.
The best way, of course, is to use maths arguments whenever possible.

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

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


More information about the core-libs-dev mailing list