Re: [RFC] Add clamp function
| From: | Larry Garfield | Date: | Fri, 22 Aug 2025 16:06:45 +0000 |
| Subject: | Re: [RFC] Add clamp function | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128530@lists.php.net to get a copy of this message | ||
On Fri, Aug 22, 2025, at 3:01 AM, Kyle Katarn wrote:
> 2025-08-20 at 14:28, Christoph M. Becker <cmbecker69@gmx.de> wrote :
>> On 20.08.2025 at 09:29, Kyle Katarn wrote:
>>
>> > 2025-08-19 14:59, Tim Düsterhus <tim@bastelstu.be> wrote :>>>
>>
>> https://wiki.php.net/rfc/howto#external_resources#rfcs_belong_to_a_single_author
>> <https://wiki.php.net/rfc/howto#external_resources%23rfcs_belong_to_a_single_authorg`µõàCæNÌ&
>> …QIJ>
>> >> (the "RFCs 'belong' to a single author") section. The existing
>> >> RFC may
>> >> only be adjusted with the original author’s consent. It might be easiest
>> >> for you to create a “clamp function v2� RFC instead.
>> >
>> > Thanks, when I go to https://wiki.php.net/RFC/clamp-v2
>> > and click "Edit the
>> > page", it says:
>> > "Sorry, you don't have enough rights to continue."
>> >
>> > Can you grant me this permission? Thanks.
>>
>> I've granted RFC karma to the kylekatarnls account; there is also a
>> kylek account, though? Can that be removed?
>>
>> Christoph
>
> Thanks, yes "kylek" account can be removed.
>
> I created https://wiki.php.net/rfc/clamp_v2 (re-using most of
> the info
> from https://wiki.php.net/rfc/clamp).
>
> Thanks for you
The grammar in this one sentence is very clumsy:
> clamp takes three arguments, a $num, $min and $max, checks if $num is within the bounds of $min
> and $max, if in range, returns the value of $num, otherwise, returns the nearest bound value, i.e.
> if $num > $max return $max, if $num < $min return $min.
Please break it up into multiple sentences so it's easier to follow. I think I follow it, but
it's clunky enough that I am not certain of it. :-)
Also, the text says $num but the code example says $value.
What determines comparability? What happens if you try to clamp values that are not comparable?
Eg:
clamp(new Point(1, 2), new Point(0, 0), new Point(5, 5));
I assume that will fail somehow, but the failure should be described explicitly.
--Larry Garfield