Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128533 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 390941A00BC for ; Fri, 22 Aug 2025 17:45:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1755884635; bh=uh7kK72fv3WU4T/l2ooa9ijtNDztZwvV5JluPXxp8J4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=VWlSAUGymxTJJevwxiR9g3wkaBWvMglit9w5wFr+TNPlTCqcOFA6FQny3dZ+QyRQI h1cTVbsWA3ERYCjcLOaSbYZSpMYz71ZzTjK9MlycjrsQ2ef34c/Cj4Vpu45mpiXhsS NCeTOaGNkvsbdUCOqbIkxJHS38qazgmU+DBinyOoAPVaUygI8kwKv0fdZiqHZeDhh+ bWNibxtdJUPXZXp0T3JszCHhh0mntn1P/bNUe8Nm38cH5Juvqid2oZy0Hu/bqrQltX eflQTTchl6WTxsLenR0yMWGi1khyp37iCkJRxMmo6JCKHGzS8U/b2xW6pgFcr0abDf QENoixdwpScjw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C447418004D for ; Fri, 22 Aug 2025 17:43:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 22 Aug 2025 17:43:54 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-b49ca2ad5cbso342338a12.3 for ; Fri, 22 Aug 2025 10:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755884727; x=1756489527; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=k9OvhaZvNF2v05YR1WXqiV6Npw+ZZADuM0yySZtW3lE=; b=H6NLsdVf2gGH73PN0QmTG9vf5zgkN2YQMyYfRTG8g7B1mCaJ0XxVno4baA4ojqpeao iL2OMJHbXMAIJzhBypW5B/XOw+dQLYO2BTK1l+v8mj5n1bTN/Vq/lmx2zF6qySbrjSf7 ipde+cMbmWlQrWF+cWti+jyha/pBiHGR1a4SVPgLxOhiCZ8wLcHkxvKy6+KLZYiRUUb7 P+N5qQTbl3i4Stlxew7JrjStlc8fxqxFvEaHqq+EpeQXDoFrczQtojE6bCx8TlvhQxom xbGJGELvM4lcSKcf4MNLvSZOMkt9CtsPP655n5qYGabSt8ThMDCUh76zuLcOLj2s761o pTpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755884727; x=1756489527; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k9OvhaZvNF2v05YR1WXqiV6Npw+ZZADuM0yySZtW3lE=; b=NXWKEfPKhUEOzEUosAFMXXwj1LNAEog44mX5orKxfPDJd6B0XkJvwnOneDum32Bwu4 AHjmzsX1HsPh0Xh3rbNgvOLIGGuRNKWmgZkcteBeA9mHbf/qb431amnMuIsaEt0nzf0m kugo5K0kDS3Hn7GlBojFKAPVhJcIQySphi/b5naWX9cbCyMXf5lDvsjqOx4/Dm3zfUt5 B0J2RlXlnwj1hw98dWAiAPIA3qEsvw1+7rgNBh8IAP0EnZ58Ty3Q8wNrQ6HYg/hkMN0/ 6jfK41sbAR0JrHy2rrMsSmP0vOGxmHEIDnoxHrFFJfBh/n1xDDFaRpPLVhjlrCjRx9rf 4jHw== X-Gm-Message-State: AOJu0YxhgUnAhXLgUGKobx5j2ZqbRS41Rk3cxpH2erINlAFDW3AuER/D TPD+Rb09RXC9q29BswPC3VfrPBU+p9WZqSPXhhNcpAxoTdfk1V0D1pEEQ93mtfmW98trG3Ut3dW xn1p21bCH4cEgM4LT6Ib9IeAdMrufmN1QQRfF9gKjLA== X-Gm-Gg: ASbGncstGZhL1NYSb+RS3Oh88YfXrCKm1ofZaeSvd94nApNXGx5nb6REqk2H2JSpZ6C KH1JmAFMd7zZFNFy1TpaQiV8Ljn4xT465DOeeIX81U9LvteQYwFM6z4lHX5kFrV3mdNIazV3u1X nTWFIt++ZgRA3PqJyJv5Jr1Rgg47BbTppywwUwiSTHL1LkurXZUSPgWJtsNGQ9uL24idlcqzIVN V5dtOIc4KqBFWU6LAw= X-Google-Smtp-Source: AGHT+IEH1XFt+2w+F6VFB53/oMwJXs0dDBNtC3AlGpSfhZ2yodcs9PMKc8v2drn6OanLEZDC1K4ezj/xGKWBttGY1Io= X-Received: by 2002:a17:902:f28d:b0:240:8f4:b35c with SMTP id d9443c01a7336-2462edd7d49mr36832635ad.10.1755884726860; Fri, 22 Aug 2025 10:45:26 -0700 (PDT) Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <0027ab13-89fb-40b4-991b-2f88a35c2f31@gmx.de> <272c241b-3145-4069-8a6a-9ea877f936c0@app.fastmail.com> In-Reply-To: <272c241b-3145-4069-8a6a-9ea877f936c0@app.fastmail.com> Date: Fri, 22 Aug 2025 19:45:15 +0200 X-Gm-Features: Ac12FXy33Bqy0uj8ixeiSSDWdgZ4z_Xpc7EyHKIfAA8q2RFTXs_VumjHUOnm9lA Message-ID: Subject: Re: [PHP-DEV] [RFC] Add clamp function To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000694284063cf7c5c8" From: kylekatarnls@gmail.com (Kyle Katarn) --000000000000694284063cf7c5c8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2025-08-22 at 18:09, Larry Garfield wrote: > On Fri, Aug 22, 2025, at 3:01 AM, Kyle Katarn wrote: > > 2025-08-20 at 14:28, Christoph M. Becker wrote : > >> On 20.08.2025 at 09:29, Kyle Katarn wrote: > >> > >> > 2025-08-19 14:59, Tim D=C3=BCsterhus 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_sing= le_author > > > >> >> (the "RFCs 'belong' to a single author") section. The existing RFC > may > >> >> only be adjusted with the original author=E2=80=99s consent. It mig= ht be > easiest > >> >> for you to create a =E2=80=9Cclamp function v2=E2=80=9D 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 $nu= m, > 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 > Ah true, $num was v1 when it accepted only int|float, I switched to $value since it's now mixed. About "What determines comparability", it follows the usual rules of PHP: https://www.php.net/manual/en/language.operators.comparison.php So it's equivalent to ($value < $min) ? $min : (($value > $max) ? $max : $value) and also equivalent to min($max, max($min, $value)) About clamp(new Point(1, 2), new Point(0, 0), new Point(5, 5)); If Point is a comparable value (simple DTO for example), it should return $value, like when doing ($value < $min) ? $min : (($value > $max) ? $max : $value) we could add a test for such case, but I think that for consistency, whatever currently works in min() should work in clamp() Following the link of the implementation, there is also a link to the documentation where I already explained the comparison rules following the example of what was done in the documentation for min() and max(): https://github.com/php/doc-en/pull/4814 --000000000000694284063cf7c5c8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
2025-08-22 at 18:09, Larry Garfield <<= a href=3D"mailto:larry@garfieldtech.com">larry@garfieldtech.com> wro= te:
On Fri, Aug 22, 2025, at 3:01 AM, Kyle Kat= arn 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=C3=BCsterhus <tim@bastelstu.be> wrote :>>&= gt;
>> https://w= iki.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_author&g= t;
>> >> (the "RFCs 'belong' to a single author"= ) section. The existing RFC may
>> >> only be adjusted with the original author=E2=80=99s conse= nt. It might be easiest
>> >> for you to create a =E2=80=9Cclamp function v2=E2=80=9D R= FC instead.
>> >
>> > Thanks, when I go to https://wiki.php.net/RFC/clamp-v= 2 and click "Edit the
>> > page", it says:
>> > "Sorry, you don't have enough rights to continue.&qu= ot;
>> >
>> > Can you grant me this permission? Thanks.
>>
>> I've granted RFC karma to the kylekatarnls account; there is a= lso a
>> kylek account, though?=C2=A0 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.=C2= =A0 I think I follow it, but it's clunky enough that I am not certain o= f it. :-)

Also, the text says $num but the code example says $value.

What determines comparability?=C2=A0 What happens if you try to clamp value= s that are not comparable?=C2=A0 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 explic= itly.

--Larry Garfield

Ah true, $num was v1 when it acce= pted only int|float, I switched to $value since it's now mixed.

= About "What determines comparability", it follows the usual rules= of PHP: https://www.php.net/manual/en/language.operators.comparison.php


--000000000000694284063cf7c5c8--