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

2023-02-08 Thread Quan Anh Mai
On Tue, 7 Feb 2023 13:30:24 GMT, Tagir F. Valeev wrote: >> A pure `int`‑only overload doesn’t have to go through the `int` → `long` →  >> `int` conversion. > > Is this a real problem? This should not be a problem with C2, and with the lower compilation levels this insignificant impact seems to

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

2023-02-07 Thread Tagir F . Valeev
On Tue, 7 Feb 2023 13:09:39 GMT, ExE Boss wrote: >> @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

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

2023-02-07 Thread ExE Boss
On Mon, 6 Feb 2023 08:44:22 GMT, Tagir F. Valeev 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:

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

2023-02-06 Thread Tagir F . Valeev
On Mon, 6 Feb 2023 09:03:48 GMT, Quan Anh Mai wrote: >> @ExE-Boss I think that immediately following `isNaN` checks give enough hint >> that we want NaN to be here. > > Ah I see, a comment explaining the intention would be helpful here, then Ok, added some explanatory comments. Hopefully they

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

2023-02-06 Thread Tagir F . Valeev
On Sun, 5 Feb 2023 18:14:28 GMT, ExE Boss wrote: >> Tagir F. Valeev has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Typo in doc fixed > > src/java.base/share/classes/java/lang/Math.java line 2215: > >> 2213: public static int

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

2023-02-06 Thread Quan Anh Mai
On Mon, 6 Feb 2023 08:46:54 GMT, Tagir F. Valeev wrote: >> That should probably include a comment then. > > @ExE-Boss I think that immediately following `isNaN` checks give enough hint > that we want NaN to be here. Ah I see, a comment explaining the intention would be helpful here, then

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

2023-02-06 Thread Tagir F . Valeev
On Sun, 5 Feb 2023 18:08:47 GMT, ExE Boss wrote: >> No. I want NaNs to go into this branch > > That should probably include a comment then. @ExE-Boss I think that immediately following `isNaN` checks give enough hint that we want NaN to be here. - PR:

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

2023-02-06 Thread Tagir F . Valeev
On Mon, 6 Feb 2023 03:25:50 GMT, Quan Anh Mai wrote: >> No. I want NaNs to go into this branch > > @amaembo Should that be `if (!(min <= max))` instead? @merykitty no. I want `min = +0.0` and `max = -0.0` to go into this branch, so we can report it. A marginal case when `min` and `max` are

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

2023-02-06 Thread Tagir F . Valeev
On Sun, 5 Feb 2023 18:13:35 GMT, ExE Boss wrote: >> Tagir F. Valeev has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Typo in doc fixed > > src/java.base/share/classes/java/lang/Math.java line 2213: > >> 2211: * @since 21 >> 2212:

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

2023-02-05 Thread Quan Anh Mai
On Sun, 5 Feb 2023 13:52:23 GMT, Tagir F. Valeev wrote: >> src/java.base/share/classes/java/lang/Math.java line 2297: >> >>> 2295: */ >>> 2296: public static float clamp(float value, float min, float max) { >>> 2297: if (!(min < max)) { >> >> Wouldn't it be more simple to

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

2023-02-05 Thread ExE Boss
On Sat, 4 Feb 2023 21:34:50 GMT, Tagir F. Valeev 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

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

2023-02-05 Thread ExE Boss
On Sun, 5 Feb 2023 13:52:23 GMT, Tagir F. Valeev wrote: >> src/java.base/share/classes/java/lang/Math.java line 2297: >> >>> 2295: */ >>> 2296: public static float clamp(float value, float min, float max) { >>> 2297: if (!(min < max)) { >> >> Wouldn't it be more simple to

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

2023-02-05 Thread Tagir F . Valeev
On Sun, 5 Feb 2023 13:45:15 GMT, Sergey Tsypanov wrote: >> Tagir F. Valeev has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Typo in doc fixed > > src/java.base/share/classes/java/lang/Math.java line 2297: > >> 2295: */ >> 2296:

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

2023-02-05 Thread Sergey Tsypanov
On Sat, 4 Feb 2023 21:34:50 GMT, Tagir F. Valeev 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

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

2023-02-04 Thread Tagir F . Valeev
On Sat, 4 Feb 2023 15:09:04 GMT, Emily wrote: >> Tagir F. Valeev has updated the pull request incrementally with one >> additional commit since the last revision: >> >> Typo in doc fixed > > src/java.base/share/classes/java/lang/Math.java line 2209: > >> 2207: * @param max maximal

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

2023-02-04 Thread Tagir F . Valeev
> 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.