On Mon, 30 Aug 2021 22:25:09 GMT, Brian Burkhalter <b...@openjdk.org> wrote:

>> Please review this PR to add officially endorsed `ceilDiv()` and `ceilMod()` 
>> methods do `j.l.[Strict]Math`.
>> 
>> Beside adding fresh tests to `test/jdk/java/lang/Math/DivModTests.java`, 
>> this PR also corrects small typos in it and exercises tests that were 
>> already present but which were never invoked.
>> Let me know if this is acceptable for a test or if there's a need of a 
>> separate issue in the JBS.
>
> src/java.base/share/classes/java/lang/Math.java line 1501:
> 
>> 1499:         // if the signs are the same and modulo not zero, round up
>> 1500:         if ((x ^ y) >= 0 && (q * y != x)) {
>> 1501:             return q + 1;
> 
> In `floorDiv()` this line is `r--` and there is only one return statement in 
> the method. I think the accepted convention is to return as soon as possible 
> like is done here, so perhaps it would be good to change `floorDiv()` to 
> match? In any cases the two should be consistent.

Yes, I tend to return as soon as possible (btw, it's a q (for quotient) rather 
than a r (for remainder).
I can of course modify the floorDiv() family to match this convention but I 
would like not to open an issue just for that. What is best?

> src/java.base/share/classes/java/lang/Math.java line 1589:
> 
>> 1587:      * <ul>
>> 1588:      *   <li>Regardless of the signs of the arguments, {@code 
>> ceilMod}(x, y)
>> 1589:      *       is zero exactly when {@code x % y} is zero as well.</li>
> 
> Do you intend to say "`ceilMod(x, y)` is zero if and only if `x % y` is 
> zero"? That is to say "exactly when" intends "if and only if"?

This is the same wording as in floorMod().
"If and only if", "exactly when", "precisely when" are usually regarded the 
same afaik. (e.g., see https://en.wikipedia.org/wiki/If_and_only_if)

> src/java.base/share/classes/java/lang/Math.java line 1591:
> 
>> 1589:      *       is zero exactly when {@code x % y} is zero as well.</li>
>> 1590:      *   <li>If neither of {@code ceilMod}(x, y) or {@code x % y} is 
>> zero,
>> 1591:      *       their results differ exactly when the signs of the 
>> arguments are the same.<br>
> 
> I would say "If neither `ceilMod(x, y)`nor `x % y` is zero".  Also same 
> question as above: by "exactly when" do you intend "if any only if"?

OK, but for consistency then even floorMod() should be changed. Would this 
require another JBS issue (or CSR)?

> src/java.base/share/classes/java/lang/Math.java line 1612:
> 
>> 1610:         // if the signs are the same and modulo not zero, adjust result
>> 1611:         if ((x ^ y) >= 0 && r != 0) {
>> 1612:             return r - y;
> 
> Similar comment as for `floorDIv()` above: `floorMod()` does `mod += y` and 
> there is only one return.

Similar comment as for floorDiv() as well.

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

PR: https://git.openjdk.java.net/jdk/pull/5285

Reply via email to