RFR: 8334755: Asymptotically faster implementation of square root algorithm [v5]

Daniel Jeliński djelinski at openjdk.org
Sun Jun 23 10:26:09 UTC 2024


On Sun, 23 Jun 2024 09:53:48 GMT, fabioromano1 <duke at openjdk.org> wrote:

>>> why the documentation does not specify that the method assumes the arguments are normalized?
>> 
>> Well, the best answer I can offer is "because no one documented it yet". `MutableBigInteger` is an internal class, so most people never see its documentation.
>>> And why the method subtract(MutableBigInteger) does not call normalize() on arguments before calling compare(MutableBigInteger)? Does subtract assume implicitly that the arguments are normalized too?
>> 
>> Most likely. If you check the code you'll notice that most methods that change the `MutableBigInteger` value (like `subtract`) call `normalize` after performing the operation, so the values should be normalized most of the time.
>
>> Most likely. If you check the code you'll notice that most methods that change the `MutableBigInteger` value (like `subtract`) call `normalize` after performing the operation, so the values should be normalized most of the time.
> 
> @djelinski Unfortunately, this is not always true. In fact, without forcing normalization before comparing, the program leads to failure in thousands of cases, while forcing the normalization resolves all the failures...
> 
> So, the question is: since it is not always guaranteed that the arguments are normalized, is it responsibility of `subtract` to normalize arguments?

Which program are you referring to?

It is the responsibility of the caller of `subtract` to ensure that the arguments are normalized. This may or may not require calling `normalize`, depending on whether the argument is normalized or not.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19710#discussion_r1650038762


More information about the core-libs-dev mailing list