RFR: 8301226: Add clamp() methods to java.lang.Math and to StrictMath [v2]

ExE Boss duke at openjdk.org
Tue Feb 7 13:12:57 UTC 2023


On Mon, 6 Feb 2023 08:44:22 GMT, Tagir F. Valeev <tvaleev at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Math.java line 2213:
>> 
>>> 2211:      * @since 21
>>> 2212:      */
>>> 2213:     public static int clamp(long value, int min, int max) {
>> 
>> There should probably also be a pure `int` overload:
>> 
>> public static int clamp(int value, int min, int max)
>
> @ExE-Boss which problem such an overload would solve? It looks like, `int clamp(long, int, int)` can be used everywhere where proposed `int clamp(int, int, int)` could be useful.

A pure `int`‑only overload doesn’t have to go through the `int` → `long` → `int` conversion.

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

PR: https://git.openjdk.org/jdk/pull/12428


More information about the core-libs-dev mailing list