Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128591 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 8A8CF1A00BC for ; Thu, 28 Aug 2025 20:36:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1756413323; bh=ipcofSnWVWqjGV26kfC+/q13p7/RP5NF9Ulht2t61Eo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=EGZaFi130BJkkjlB81LjRp1yTr0i7lqv39cWWftx4+JOf5x4nwBDHaK5TQaQ+fDIo VKdHcLx4d+hJsmyhUywSvkNqYWpl5VtisgwTptbY4mmBvkr3pfTavDM9C919bkwfuG IMkZ333UuxAd/H/GxidEiuUzQHD9ltZlynjwrRU9GhazPu6aMMMed7AJWPptBYJ52z FKkUDUtV296o6hSvJWln2mRD40tNQAEaH8MLLmrRbSPDEepaI4hl5HOLwGcm7WA/St kBeQS29QhA4VquR4PiZ6NFywEfi93/l/ZDs0wP48lrD6jpGyxtWpDX1jO9dbp93GXh zoyi5WYcRNp5Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 55016180087 for ; Thu, 28 Aug 2025 20:35:22 +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.2 required=5.0 tests=BAYES_20,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 20:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1756413411; bh=eMer+92vWAmZ258FNMa12Ixrw+8q7NAgdhmcAAG45XE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=lD2SqY65sg8EcR2YiPLyJY86Nv+K6kvLuF1arXUhBg+DL2syf9PPjnkHkIfixdJH4 qupfxb6G0/RHXU42SgUd7VGUr7JMpXvHMSWNH2YuS7baZhXAWc+6aRG8KDgs8o/xg8 RIxaMeyPoyllzKLeY8AhA7CIkDzHjaRJTnoMczqIIEut9LF0XEpHT7KJtR1MaZ/BW/ jCzNP95qDW+9chlHB8ElZNk6I357mEKbFUifzsdRR6ERHqOwNIZobHDgIWrKuGtL6n hvIVhmr2j0lSMCPRZ0BNrguv2lzSuIQVsCt8hTovpeCNJ8dkfKzIQ+shMU9lixr7r2 lLbl4ZzlaEDZQ== Message-ID: Date: Thu, 28 Aug 2025 22:36:50 +0200 Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [Discussion] Add clamp function To: Kyle Katarn Cc: Hans Krentel , ocramius@gmail.com, PHP Internals References: <1756361767126.3727989781.4204927711@yahoo.de> <3b1bd29cd42074b499d38e10cb97bf42@bastelstu.be> Content-Language: en-US In-Reply-To: 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 On 8/28/25 20:26, Kyle Katarn wrote: > Just my opinion but the function aims to provide an alternative to > min(max()) that would be: > - easier to read > - faster to execute > > If having many different behaviors depending on an option and so a lot of > if-else path complexity, then it will tend to defeat the second goal. I Adding an additional parameter to switch between 4 modes of comparison hardly qualifies as “a lot of if-else path complexity”. That can be done with a single `switch()` statement. I doubt that you can measure a meaningful difference in speed and if you can, then it's still possible to optimize based on the expected path (i.e. closed intervals). Since a big part of your argument in favor of the clamp() function is “performance” (both in your reply here and in the introduction to the RFC): Please add meaningful benchmarks to the RFC text that show how much faster clamp() is actually going to be compared to alternative solutions. > would add it if there is a strong interest, otherwise I'd rather stick to a > minimalist implementation (like seen in most languages where clamp() is > available. Best regards Tim Düsterhus