On Tue, 7 Feb 2023 10:24:24 GMT, Tagir F. Valeev <[email protected]> wrote:
>> clamp() methods added to Math and StrictMath
>>
>> `int clamp(long, int, int)` is somewhat different, as it accepts a `long`
>> value and safely clamps it to an `int` range. Other overloads work with a
>> particular type (long, float and double). Using similar approach in other
>> cases (e.g. `float clamp(double, float, float)`) may cause accidental
>> precision loss even if the value is within range, so I decided to avoid this.
>>
>> In all cases, `max >= min` precondition should met. For double and float we
>> additionally order `-0.0 < 0.0`, similarly to what Math.max or
>> Double.compare do. In double and float overloads I try to keep at most one
>> arg-check comparison on common path, so the order of checks might look
>> unusual.
>>
>> For tests, I noticed that tests in java/lang/Math don't use any testing
>> framework (even newer tests), so I somehow mimic the approach of neighbour
>> tests.
>
> Tagir F. Valeev has updated the pull request incrementally with one
> additional commit since the last revision:
>
> Whitespace fixed
test/jdk/java/lang/Math/Clamp.java line 149:
> 147: {-0.0, 0.0, 0.0, 0.0},
> 148: {0.0, 0.0, 0.0, 0.0},
> 149: {1.0, 0.0, 0.0, 0.0},
What about adding similar tests for the [-0.0, -0.0] interval?
test/jdk/java/lang/Math/Clamp.java line 160:
> 158: {0.0, Double.NaN, 0.0},
> 159: {Double.NaN, 1.0, 0.0},
> 160: {0.0, 0.0, -0.0}
Perhaps add other empty intervals, like [1.0, -1.0]
-------------
PR: https://git.openjdk.org/jdk/pull/12428