Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128580 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 D40281A00BC for ; Thu, 28 Aug 2025 07:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756366573; bh=j47Oq36nHNVcHyrYmUaeCkGVStwiNvvYSzxnU5gjZCU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QlOBnrs3dLF8fBQ615xBrUXzX1b8PwyYu5MrudQUaUJI1NKVuh2YnGbOltOYBgfKO M8l092l29KJgCjlplVza3Iatyeo0lHejqsPRcx3PsQVyoa1yLEuwjftcao238e7tiV ODiJa6AQ2b6vr6j/JB9b+V/0y0ZsrWpM9ElB0/7I8ZHpB2tNlbXB21vNXGrv7jZ5l1 xXLpmzFOtR70gIY6OEiMZixNAWeSv/rW529w17h75i/gqNkivkwcnF/YG8mEIFsy2d +7kbZDbykeFijbb1F6Z3ptbVmOX0mh2Bn4Yw9BVb+otN2tSOJ0I+zuviEnEPila5Yb +rAvijxPgyMnA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 07200180032 for ; Thu, 28 Aug 2025 07:36:13 +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.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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 07:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1756366663; bh=ZAYf2zovgi0HD5YiuJ7CNbMcWSwmUL8FdUZcfjbWPZ4=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=YjqUTMm4hUdgClC72YI9Y1GtxvWLYUInU+3casKsKXcqxNi+lEAlA3zTK8wWIIvRf K96MUFMU26v7/p5DP5GSOo+1uUa+ZXHTS3K/AfojTD9yuZ7XifyKtsFYcWVQqZpFB9 jrad8dPHmzn6QkF3+zzZ3CDKjSSCyzz0Zgx2pneMdx3BcjyMFUxugFrXEEUhYaUHpQ xJR30/kM8GcgGbNNuRVh3y1l9t7U5DDgzQZGfQ9/nKrO6bDiX67ClYaAoL7u2ACSzG ekKtf/ID1i/k1udwBKc6LESs5UHR3LKkPOSi1uofJG7rAojdgLqITLHJn5mVXKnpI8 SVUjh4NqXVXsg== Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 28 Aug 2025 09:37:43 +0200 To: Hans Krentel Cc: ocramius@gmail.com, Kyle Katarn , PHP Internals Subject: Re: [PHP-DEV] [RFC] [Discussion] Add clamp function In-Reply-To: <1756361767126.3727989781.4204927711@yahoo.de> References: <1756361767126.3727989781.4204927711@yahoo.de> Message-ID: <3b1bd29cd42074b499d38e10cb97bf42@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2025-08-28 08:35, schrieb Hans Krentel: > This also highlights a minor but important clarification for the > documentation. To make the behavior perfectly unambiguous, I suggest > a small edit to explicitly state the bounds are inclusive. This is a good point and I agree that it should be spelled out explicitly. However to me this also raises the question if the interval boundaries should be configurable to switch between closed intervals and (half-)open intervals. For many applications of continuous values a right-open interval (excluding the upper boundary) is more useful, since this makes it easy to generate non-overlapping ranges (e.g. to clamp to a given day when passing DateTimeImmutable). This would also provide an additional value-add over the min-max construction, where the boundaries would need to be calculated manually, which is super complicated to do in userland for floats. There's precedent in ext/random with the Randomizer::getFloat() method that takes a Random\IntervalBoundary enum to decide on the the interpretation of the boundary values. Translated to `clamp()` this could mean: $value = 1.0; clamp($value, 0.0, 1.0, IntervalBoundary::ClosedOpen); // 0.999999999999999888978 Best regards Tim Düsterhus