Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121008 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56414 invoked from network); 7 Sep 2023 20:10:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Sep 2023 20:10:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F9571804AC for ; Thu, 7 Sep 2023 13:10:28 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 7 Sep 2023 13:10:24 -0700 (PDT) Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-26f4bc74131so938411a91.1 for ; Thu, 07 Sep 2023 13:10:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694117423; x=1694722223; 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=XZzVRlSdqUo0/ajqEVLarJE746Xt8XvHmFkkO33stA0=; b=VKDhpgO6jcltyWv3xXr2AjhSNdk4vE8oAnB0Z95mErl1S0DXkheLi+dA4bQP1VX+FB jF7h7OfcfDfWo+E1IV/oVAy2kCu1rSyj1vo7DZhQxUHAdfSbH8ZO/4DAAvwS4kNNV4Q4 Ohp/25d/Axrosr89cbmkPOOg+83zGzqUyrbaBi9qzeLcXxlYYKjeMzkoTO3AkOsijXX0 t+eQLfS7y77w7MEfENpauU2IlZnvNCqXAoNB0YjkNDTBe8B2YEIke6xzFNyIVNKyaoMS gyW6lDYxw09CT1I6SzNSG/dgLyEd0woZ4LqS7dMtpJDbpbAY5Vv78uzb15cLpuVpICN7 7Klg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694117423; x=1694722223; 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=XZzVRlSdqUo0/ajqEVLarJE746Xt8XvHmFkkO33stA0=; b=pV+/RutINjY3tHORGu4SdQKnlfYgBBi7Zx0fRDuhEOAi9z6nqLLog8roGMIJZWdeYA qTpyH7xNvHdYqqH0IxCX5CuLd6aIalX/WmzMmF7UfmdJx+SIJNfmYRqTUbjP9WWZSA29 px6M152uL4sS9fGdp72rLrFZ8K7oFLtf4budsVNyTVx3deF+exOCcBWYLiA5xXMUTywG kFRfRQ403LufgK7CtV5bJOgg7YpCyc8JQkG029Zc0J7D4YVkhkmG5omWNN0P6tbozlVm 7ushevGAYvU9Qf9aY5Qzv5jSsovvXcQtKnkdCffdemkrb593KFHSvxBGIbYLvjzkbVpB gNIw== X-Gm-Message-State: AOJu0YztL2aoRhCqMn9p/fzFmxbpzXcJyBhJgrKdc+v+XwGQ7onMiQv5 Of0rBdRDfOAQ55V/UbMZI0WryAol4p8GCnYnY5g= X-Google-Smtp-Source: AGHT+IFPRJQ9pNzjoGinYM9qnpUD/UmjpRgifyg/sdnbqxqYplUgMaURXO48Vhn2bb/3jKwCqS5qudX2nFKOF/PESdI= X-Received: by 2002:a17:90b:1c0f:b0:271:78a0:8ab2 with SMTP id oc15-20020a17090b1c0f00b0027178a08ab2mr4179655pjb.24.1694117423483; Thu, 07 Sep 2023 13:10:23 -0700 (PDT) MIME-Version: 1.0 References: <7f23f0ac-bba6-5997-b737-2a252205cf85@bastelstu.be> In-Reply-To: Date: Thu, 7 Sep 2023 10:10:11 -1000 Message-ID: To: =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Cc: =?UTF-8?Q?Tim_D=C3=BCsterhus?= , Jorg Sowa , PHP internals Content-Type: multipart/alternative; boundary="0000000000003c0f5f0604ca7392" Subject: Re: [PHP-DEV] [RFC] [Discussion] Add 4 new rounding modes to round() function From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000003c0f5f0604ca7392 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Sep 3, 2023 at 5:51=E2=80=AFAM Alexandru P=C4=83tr=C4=83nescu wrote: > Hi! > > On Sun, Sep 3, 2023 at 3:14=E2=80=AFPM Tim D=C3=BCsterhus wrote: > > > > > The RFC mentions already has a section with regard to naming: > > > > > Why not the names PHP_ROUND_UP and PHP_ROUND_DOWN > > > > I generally agree with the argument in favor of the names you've chosen= . > > However they are inconsistent with the existing 'PHP_ROUND_HALF_UP' / > > DOWN constants. > > > > I don't want to create extra work for you, but I wonder if additionally > > one of the following should be done: > > > > - Creating PHP_ROUND_HALF_AWAY_FROM_ZERO as an alias for > > PHP_ROUND_HALF_UP (and likewise for HALF_DOWN). > > > > > I believe consistency is important and using UP for "away from zero" and > DOWN for "towards zero" sounds good to me. That was so far used > consistently everywhere, as far as I'm aware. > Documentation is very clear about what they mean, and you can always thin= k > that both positive infinity and negative infinity are up while zero is > down. > > Yes, we can have some extra constants for the four ones that contain "up" > or "down" with "away from zero" and "towards zero", but I find it > unnecessary. > As someone who maintains a math library in PHP that has its own expanded rounding implementation, I will politely disagree. Away from zero, towards zero, towards positive infinity, and towards negative infinity are completely and utterly unambiguous and provide the developer with precise control over what behavior they want. I don't see a reason to use something that we KNOW is ambiguous when we're designing it. This becomes even more important if we ever wanted to provide even more rounding modes. For instance, a PHP_ROUND_HALF_ALTERNATING would want to explicitly use positive and negative infinity as its directions most likely. (The purpose of a "half alternating" mode is to ensure that the introduced error by rounding many numbers doesn't have a directional bias by swapping between two modes that round in one direction and then the other.) I don't want to complicate this RFC, but I wouldn't mind adding a PHP_ROUND_STOCHASTIC mode later either. (This mode would round 1.7 to 2 for 70% of executions and 1 for 30% of executions. The purpose of this rounding mode is to ensure that if you averaged the same number being rounded over and over, it would average to your original unrounded number, and is used in many Machine Learning applications.) Jordan --0000000000003c0f5f0604ca7392--