Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128590 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 770E81A00BC for ; Thu, 28 Aug 2025 19:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756410428; bh=7qEEzYUoCfagjIfvg4+29zKAEWBmfgVe+WGgvJf5C5M=; h=Date:From:To:In-Reply-To:References:Subject:From; b=W6ciOOfIEbBMp0r244mWFEm5BnhkskOii07IcC/yJMA++Lgz9hsU7Yh9DVgX7SOak sSkCXkCQXZYrCRY98JQFQDhhNGugOwl813vU8JMnTdBa5JLJ1jMV3KynA5A6/BkGD0 /DfpRAqZrCQEI8SOFmLiAhh/9ABTR8ZDN2rajTYjERZGOpk5suWTfDZbW1wBgEhRhk aob0FCMT3TSCg4xAR8BmKkMWZvn+bxrKLy0t3zXf4QqqXCloYcs+XajMFQRkDxy8Bn PZ9Y5McRy43gO2wuyanf5NyZMT72KwsfX2QcN5NY2gK02roOm5ENr4JN0LsXejCISu MdKLy6Klm+zaQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9F00E180068 for ; Thu, 28 Aug 2025 19:47:07 +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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a1-smtp.messagingengine.com (fhigh-a1-smtp.messagingengine.com [103.168.172.152]) (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 ; Thu, 28 Aug 2025 19:47:07 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7D6D314000ED for ; Thu, 28 Aug 2025 15:48:38 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Thu, 28 Aug 2025 15:48:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm1; t=1756410518; x=1756496918; bh=xxHdiQU0U6o2xTcsk6KwJ hD5KJGVrZZp08A8z+OiAqU=; b=jyLNm2v443xWRY5j1LfmC2vGFlex5ZHplpF1/ iIkAmKx+BSEbr0OYYn+qic4TW+Yp+DQdhRP70zd1dpUzL6J64iGtOWcQnR1ig7Ph rwnqq1BsJqKkx0GtjiMd8Rw+v7Oie16iZinGLtV3M6uZNgQJWrbqhaShKN040sZA GlqzN1pJE9zcdnqg1s/ZI9jZnc+Nfbyca+hnpMvn43/bINrbv5OfUdQMHZoC5y/R xMvfHEHO+kvDN6FilENDgVfCimQadIcv7OR83OYgiDsDNYOeR+l0Bwb183AML3+l cbUgcnEvyg99KU6IhURwvl1udaB5l3FJtCY+DAMP3+j6vz/Kw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1756410518; x=1756496918; bh=x xHdiQU0U6o2xTcsk6KwJhD5KJGVrZZp08A8z+OiAqU=; b=LAoGB95i4APfBCT4v ngNAHwmjreuqtBdpgbDXloXqV43PyFIuxRraa9D4dDNsMP6Z8iVE+GMlElkjea1z /up3yQ1fS9hvF2hgkUSqiFvE74WbWAGHxKwyB12/u6nx0SCahg5ABzy+KLxqt7A/ Fgq1Q7qkA9E3g/mSRhWEuxMQ/rPFmVIlXqf/jkCrIGklj0xDUNd+toahyd2Sg/Ni TN4ZIyJSnoLgZgzhIt1Mq1HmfXZ0iAoeCoiWqxkbaPFs51DZ7LQfgJJ2iPilYVgn P7k3DiBGwJdg1MEy+q59l5g0Bj12gy2XZ3SqX3jCoLdB/8vRFI/mXIXKKYbEcxwn AkY2Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddukedukeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeffieeivdfhvdeguddttdegteeiueegvefhteehfeeffeet udeitdehtdegjeeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomhdpnhgspghrtghp thhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghlsh eslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 238AA700068; Thu, 28 Aug 2025 15:48:38 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AAi9W-atQONs Date: Thu, 28 Aug 2025 14:48:17 -0500 To: "php internals" Message-ID: In-Reply-To: References: <1756361767126.3727989781.4204927711@yahoo.de> <3b1bd29cd42074b499d38e10cb97bf42@bastelstu.be> Subject: Re: [PHP-DEV] [RFC] [Discussion] Add clamp function Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Thu, Aug 28, 2025, at 1:26 PM, Kyle Katarn wrote: > Hi, > > 2025-08-28 at 09:37, Tim D=C3=BCsterhus wrote : >> There's precedent in ext/random with the Randomizer::getFloat() metho= d=20 >> that takes a Random\IntervalBoundary enum to decide on the the=20 >> interpretation of the boundary values. Translated to `clamp()` this=20 >> could mean: >>=20 >> $value =3D 1.0; >> clamp($value, 0.0, 1.0, IntervalBoundary::ClosedOpen); //=20 >> 0.999999999999999888978 >>=20 >> Best regards >> Tim D=C3=BCsterhus > > Just my opinion but the function aims to provide an alternative to=20 > min(max()) that would be: > - easier to read > - faster to execute > > If having many different behaviors depending on an option and so a lot=20 > of if-else path complexity, then it will tend to defeat the second=20 > goal. I would add it if there is a strong interest, otherwise I'd=20 > rather stick to a minimalist implementation (like seen in most=20 > languages where clamp() is available. I would also favor the minimalist/traditional/like-everyone-else approac= h. I wondered at first if open/closed boundaries made sense, but on con= sideration, that's not what clamp() traditionally does. It's just min/m= ax shortcutting. So let's just do min/max shortcutting and move on with= life. --Larry Garfield