Re: [RFC] [Discussion] Add clamp function
| From: | Bob Weinand | Date: | Wed, 27 Aug 2025 16:48:16 +0000 |
| Subject: | Re: [RFC] [Discussion] Add clamp function | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128575@lists.php.net to get a copy of this message | ||
Thanks Larry!
On 27.8.2025 18:40:51, Larry Garfield wrote:
On Wed, Aug 27, 2025, at 11:06 AM, Bob Weinand wrote:Indeed, that makes sense then. I must admit that I've only ever been using the clamp from CSS, but never from other languages. (I still think value in the middle makes more sense, but I guess that's me then, and I won't object.) Then yes, please note it in the RFC :-) BobHey, On 27.8.2025 15:34:53, Kyle Katarn wrote:Some quick data points from momentary googling: CSS: clamp(min, val, max) Python: clamp(val, min, max) C++: clamp(val, min, max) Java: clamp(val, in, max) Javascript: clamp(val, min, max) C#: clamp(val, min, max) Kotlin: val.clamp(min, max) (as an extension function) Ruby: val.clamp(min, max) So it looks like CSS is the oddball here. We should follow the clear majority approach. (Kyle, feel free to include this in the RFC.) --Larry GarfieldHello, I handled the feedback received on the draft RCF https://wiki.php.net/rfc/clamp_v2 If I didn't forget anything this should be now ready for discussion. So I updated its status. There is an implementation proposal: https://github.com/php/php-src/pull/19434 And some draft for documentation here: https://github.com/php/doc-en/pull/4814 Thanks,As others have noted before, what's the motivation of having the to-be-clamped value as first parameter rather than infixed between min and max? E.g. from CSS: https://developer.mozilla.org/en-US/docs/Web/CSS/clamp:clamp(min, val, max)Feels to me as the most natural order, too. You mention it was taken from the first RFC, but that one also did not discuss the ordering in the first place either.