Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115050 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44361 invoked from network); 23 Jun 2021 00:07:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jun 2021 00:07:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 61C981804DA for ; Tue, 22 Jun 2021 17:25:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 22 Jun 2021 17:25:32 -0700 (PDT) Received: by mail-lj1-f170.google.com with SMTP id c11so578901ljd.6 for ; Tue, 22 Jun 2021 17:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:message-id:date:to; bh=6U2/XWNb9scJmZgEE7a7JXRs6rtVZGVe9+Kkrw1MvPY=; b=S1aNBvavNvwbEe/NCAvieZrfagHbzFJYIvJEWDXRZrq+jFjD+2S8g5PbCoj6yJ8Aa4 HRvZfNuccWcGhPajlMNvlgXPA9bU1fLyPm9bXI7kh7xAS28JUANc7lUqzXFfZ2pariGC XiULXxjZLRPlp74M33aerzkcJXMYzTe2JOWMU5QokHhm8+yKNeM8ZtYOOI4ppBXVT0RA VQQpczWf/meZ6lyJU8i/Voao25NQwW7A7iK+GkEc/U98ulrS2trZAwcWOjEvdkvTxOz0 zROiEPzlwQy9CoBC2ClJCexIfW31YIERpzfhMIykWWsghdteWqZb52nJ5666+9HyLN64 mmwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:to; bh=6U2/XWNb9scJmZgEE7a7JXRs6rtVZGVe9+Kkrw1MvPY=; b=XoWk4vwFOECc50S/2CYA331yDI11MFydMW/2Cjjayz+EjBuWREcuziHA59a4b0rXpx HtAM4BVeh5Lz+JJh50slPU3Vht7UItmcux4OI1o6vLgjfnpwh+/fWaFwtIjU5H5Sb4rK KPlwkzRcobLjy6pQd4JaELjLNh7gBGNXY5tLUlo7j5uD0SNyRFH+2lTdhVGCbDLedHqD tNqUudPyTvhfbHMKfTFG3t9H3+7KUsYziszixaxCIZ6ZZtQcLOMluuZMZ6oAFvHz6Kjx LI3h+WAa8er/ivgMOZfYaYvuB/6knuyqWdCEb8VZ/jsYSaYnDQ+98B/zFnsCjQwwyU8C Hl6A== X-Gm-Message-State: AOAM531fEJXG9+vE0YDGrAzM3xUQG8FNAQ0nZxIuIt3RRVPOGQ3MGhrL XR2IBPpYCDq6DHXgalu22Tvor1JvjaU= X-Google-Smtp-Source: ABdhPJxsNi9SjXQpD9YX7MUM29XWlJZo+w2fhWJCBsTlvwItmh9uJmgU/e650pIrjwwn6OWh2QcDvA== X-Received: by 2002:a2e:2c17:: with SMTP id s23mr5619206ljs.296.1624407927842; Tue, 22 Jun 2021 17:25:27 -0700 (PDT) Received: from [192.168.2.137] (81-233-163-178-no84.tbcn.telia.com. [81.233.163.178]) by smtp.gmail.com with ESMTPSA id z30sm2359687lfu.42.2021.06.22.17.25.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jun 2021 17:25:27 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_221EB12E-CEB5-439B-8828-3CD74E96CF40" Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.7\)) Message-ID: <1014AE76-B3D5-48F7-A0F0-B8E3327123A2@gmail.com> Date: Wed, 23 Jun 2021 02:25:26 +0200 To: internals@lists.php.net X-Mailer: Apple Mail (2.3445.9.7) Subject: Proposal: clamp From: hallbergkim@gmail.com (Kim Hallberg) --Apple-Mail=_221EB12E-CEB5-439B-8828-3CD74E96CF40 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Greetings internals, I present to you a proposal for a new basic math function: clamp. The main goal of this function is to contain a number inside a given = bound. And return the number if it is inside of that bound, and if not, and the=20= number is outside of the given bound, the nearest bound is returned. Now, does this need an RFC? The behaviour can be implemented in userland=20= in a number of ways, one of which is to compare the values in a if = statement. Another is to use the min and max math functions. max($min, min($max, $num)); I don=E2=80=99t have any schpeel as to why this should be in core, only = that I thought it already was. Considering it is part of other languages standard math library, and it = is a useful function. Can see this being useful in image manipulation, server-side rendering = and math just to name few. The proposed signature follows the convention of other math related = functions. function clamp(int|float $num, int|float $min, int|float $max): = int|float {} This function is very easy to implement, has no side effects or backward compatibility issues, unless a userland implementation already has the = function declared, in which case PHP will throw a fatal error since the function cannot be = redeclared. I've implemented this feature a few months ago already. - Link: https://github.com/thinkverse/php-src/pull/1 = What are your opinions on this function? Regards, Kim Hallberg. --Apple-Mail=_221EB12E-CEB5-439B-8828-3CD74E96CF40--