Integrated: 8271599: Javadoc of floorDiv() and floorMod() families is inaccurate in some places
Raffaello Giulietti
github.com+70726043+rgiulietti at openjdk.java.net
Wed Aug 4 17:19:37 UTC 2021
On Mon, 2 Aug 2021 22:34:58 GMT, Raffaello Giulietti <github.com+70726043+rgiulietti at openjdk.org> wrote:
> Hello,
>
> please review the changes in documentation of floorDiv() and floorMod() in all their variants. Some are clarifications, some are corrections.
>
> Here's an example of a confusing formulation in the current doc
>> "the / operator returns the integer closest to zero"
>
> Literally, the integer closest to zero is zero!
>
>
> The doc of floorMod(int, int) also states:
>> "If the signs of arguments are unknown and a positive modulus
>> is needed it can be computed as (floorMod(x, y) + abs(y)) % abs(y)."
>
> That's a questionable advice, as the sum in parentheses can lead to irrecoverable overflow (beside requiring two divisions instead of one).
> E.g., setting x = Integer.MAX_VALUE - 1, y = Integer.MAX_VALUE leads to the quite incorrect result -3, which is not even positive!
>
>
> Greetings
> Raffaello
This pull request has now been integrated.
Changeset: 9f1edafa
Author: Raffaello Giulietti <raffaello.giulietti at gmail.com>
Committer: Brian Burkhalter <bpb at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/9f1edafac4f096977ea6ce075ae7a6b0c2112b7d
Stats: 50 lines in 2 files changed: 6 ins; 7 del; 37 mod
8271599: Javadoc of floorDiv() and floorMod() families is inaccurate in some places
Reviewed-by: darcy, bpb
-------------
PR: https://git.openjdk.java.net/jdk/pull/4963
More information about the core-libs-dev
mailing list