Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128542 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 6B93A1A00BC for ; Sun, 24 Aug 2025 14:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756045564; bh=dMIA2x22weJEsZVID/za5wCZN2mZWLKmIroND72iT9w=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=SeGCcMFxjvKXLwx3SLWVdvdsWhrv6gcuQ9Qu92iKtuc6k3qTewxepiDBQQY++CIho ZyncnnA52K8+XcyLzG1843FLuBk2k4jSDdXitlXSe3UoMM5ti57DCtiabIsEsyrP+n 3pK1gTCyJqp7wKY9Pl4gHnPRD87MNdhBsIAzixfg0T9hehRGb288BuM9xedO48lXKf z3ZaejOFrVR/VmZwcjnBVhVDXRQLkd4qOUa8bEzIwYSkPE8z+jIW3dxsjFes9h74oC pWrWliXE+6ejI07StPhdL/Eb3UYeAA9P2/FHw8mfWY9NU9N5wCI3E9WI6+7N0RIaLh iMzB7UTcBxYOg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F346C18005C for ; Sun, 24 Aug 2025 14:26:03 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 ; Sun, 24 Aug 2025 14:25:53 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-b47173749dbso2480048a12.1 for ; Sun, 24 Aug 2025 07:27:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756045646; x=1756650446; 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=N7SKTFCvltkbCr9EfPbKOblsTUdIz3K4CMjJaSL9HJ4=; b=XSVOPXCrByEMae443kOwM339vPghUUw++6YrBNUKG20HdngJlan/szLCea+qWk2g9Z 0pPxi7xFMG57lH7NyHHfTeSOOTgf9QP80J1X/yMJIwzSzDfh+/VRy4wYjBhBhQ344CH8 UCuSU2IPtb1ZpKLMg5rjvFNLNk7qUrfkgLrf8wcwwF/85Ws0Br3ZZ5Lu3kKLOsETcGte gEBe8LM4pxJZoaar0RhmML5lhkENcYUYSUQFRxfQIy8r+Kvc7BUiWT0QpDnekvA+NVBv Qi5YKvd+VRxCGa79+wldABLpYEQfU59A4b2EzE8kCEBEaSFbtsPR9i9BXXkOVu25Twlb gIfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756045646; x=1756650446; 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=N7SKTFCvltkbCr9EfPbKOblsTUdIz3K4CMjJaSL9HJ4=; b=rQ3FdxgNHNV9v7GrFBCP60ojUKahCCU5S/67j4llr/BzDgn5yS04GnQ6epDsmaU1ww rOZ0eS9hse94nuzGXpmggsKlT8w+3clceGKM9hNnLeb+aGdB137OHoh9xYoeHZDHOEBW xjM5X4vIDl0xIQxrBzdMrmOUUUAE5znXnkglEyzGy++UkR4QlCmJ6+2mbe3aM7cVxAtV NapBch4N24k9A9+hT8hsYe5WDMM/aFDafsVndJFP8lv8wqNzhq1bMdt1jQH8rWvEdW5f vBui038uxsinjEF4Y97AbM6Ria6XgB2JTi52889ALZP+iTBmYV6TEwzO02yxUfS7L3+0 G0vw== X-Gm-Message-State: AOJu0Yy6s7q1L7amq5Ux30fKtO69jnsby5WK7LqnJ5x5U0IU2bBE8BxC rh6HE9i82kJipPGSWCL24ZGtQZj9AndUDS0NzFi/7GaZrUmAImqHMHXpi+LPhvRdWpAwEPt1IYa iHXTGLwEamLfAmB440GQ5SVwJDA1xvbbFFNiitP8= X-Gm-Gg: ASbGnctgoKZCIFG+9fD+4cJVoQeEB9dKiICmbYIev56dPDEpIHD5qQ2Kiq3vs0gqMc1 jHns5IyaITlX0yGbN4TRLX8u+FMx+jYOE8hKEFTbEBKPntsvaPwEZz/mSTmkCBNpifqq0rF3Vgz C+k2h7PENTAATWaFUFEcJ0bAoZVdvOJ4WOr8zi80AoPa74zlyjn55Y3tMqMVLGyzEJygz80hcY/ r+LN4dzYA== X-Google-Smtp-Source: AGHT+IFjyQk2PQQMC6DV2u7oc7bE6/NrNiJNxw+hdjELEetqGJPxciAHqHdyS4k/VHuFrx0LY6YAhiG/ELM4SZ0GM08= X-Received: by 2002:a17:902:e806:b0:246:d743:b0e2 with SMTP id d9443c01a7336-246d743be6fmr6051155ad.19.1756045645603; Sun, 24 Aug 2025 07:27:25 -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> <011001dc1358$287f1860$797d4920$@glaive.pro> <70b0d91d-c415-42b5-b02d-7e346efaea01@varteg.nz> In-Reply-To: <70b0d91d-c415-42b5-b02d-7e346efaea01@varteg.nz> Date: Sun, 24 Aug 2025 16:27:15 +0200 X-Gm-Features: Ac12FXwsdIK6MpgX0_-kjbKXkyHBpgGHvOSGdFX4Zo6U20mbF_K3MZTzUJmzGbo Message-ID: Subject: Re: [PHP-DEV] [RFC] Add clamp function To: Weedpacket@varteg.nz Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000ea67ab063d1d3c42" From: kylekatarnls@gmail.com (Kyle Katarn) --000000000000ea67ab063d1d3c42 Content-Type: text/plain; charset="UTF-8" 2025-08-22 at 22:29, Morgan wrote: > On 2025-08-23 05:29, Kyle Katarn wrote: > > > > Also from my point of view, min($max, max($min, $value)) has a counter- > > intuitive reading when used to clamp a value. > > Well, that's trivial to deal with: > > min(max($min, $value), $max)); > It's not just about the order of parameters, it's still not intuitive to call max() with $min and min() with $max, you still have to think about what it does step by step to make sense out of it, while clamp($value, min: $min, $max) or clamp(min: $min, value: $value, max: $max) will provide a syntax that immediately make sense for next reader. Like the author of the RFC v1 also mentioned, min(max()) is inefficient (see the inner complexity of those functions). --000000000000ea67ab063d1d3c42 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
2025-08-22 at 22:29, Morgan <Weedpacket@varteg.nz> wrote:
<= div class=3D"gmail_quote gmail_quote_container">
On 2025-08-23 05:29, Kyle Katarn wrote:
>
> Also from my point of view,=C2=A0 min($max, max($min, $value)) has a c= ounter-
> intuitive reading when used to clamp a value.

Well, that's trivial to deal with:

min(max($min, $value), $max));

It's= not just about the order of parameters, it's still not intuitive to ca= ll max() with $min and min() with $max, you still have to think=C2=A0about = what it does step by step to make sense out of it, while clamp($value, min:= $min, $max) or clamp(min: $min, value: $value, max: $max) will provide a s= yntax that immediately make sense for next reader.

Like the author of the RFC v1 also mentioned, min(max()) is inefficient (s= ee the inner complexity of those functions).=C2=A0
--000000000000ea67ab063d1d3c42--