Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120862 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 39254 invoked from network); 23 Jul 2023 18:40:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jul 2023 18:40:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5A2AF1804F2 for ; Sun, 23 Jul 2023 11:40:23 -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-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 ; Sun, 23 Jul 2023 11:40:22 -0700 (PDT) Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-56368c40e8eso2253720eaf.0 for ; Sun, 23 Jul 2023 11:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690137622; x=1690742422; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=jAFErQSSW+1OXUm13964Z9UkX86PpBU154xnbfuXUCI=; b=pK4U2A/XtbFN0zDQEIXYbcRsz7zPO2tMcD8JKf43IuftASOyVlSiuPROfvrfiDutg+ 3lH4cJ8zGu0xoEBnGlR6xz1fkoMtZqSf/tpqEgAlN8Ew7w12d5vQDHCS8DmMPq+kpqqx uwRRCPFaBkd3Ha/oK6p476AK249XUBEjFeKbTBrgHsNuLzfVxzq9zrxqff3pupC4ioUD 5sTotCSKJOkxMn5sCtGgWDV2BB/gkVBYYUaYjJRIXPuVblMNfjXbS75FDCKQbugHkyLi LUE0Cqlnw0rm1/jQNFIKPywkGbVpPscKcd3dP8+XMNDAhkH/JpNsP6K+EGcc2e0E8Yg3 H5cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690137622; x=1690742422; 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=jAFErQSSW+1OXUm13964Z9UkX86PpBU154xnbfuXUCI=; b=JHsmbvAHb/NBdQaPvBJAosRbfOYIvWS/Sc6uKmiqJfN6XBXOYigLKPELemCgEMtZg6 Wse1uoyzs8Z+aCvmQDYPxfWHmKhir9Hltck+4DEes3U9/SDvBVl7lyqFs3FDxazuzoZq Qj7d1J9U8nt+nW2mmepEer6R9c/C9fylchQWlFCojNvG9UyBPqiNBQulFVtpImYAVmnN cpdXsTu+IowABLOLwdB3HE/S8Wcq3kyW7ykyV0+t8LDn/NHl0o5hMtRKLZHdInd/oW6s nB/8re+p0J2w19kCeEMUKC7hsqbUUgoHrA7lnzpx8VbXfbxmVauTI8gnTlwdH+Iy5R+h ntdg== X-Gm-Message-State: ABy/qLYqne+HSyva34oI3gqe+YWl+bNSLFtdVCU64YDUUik5hbBqX/4/ fGJsozOH3n78KTL/mnwEKbgWNbHemVedGr25zoU= X-Google-Smtp-Source: APBJJlEFxmaWIX1V3ktqfm8+EZZaJyWAszLpCk+44VSISRZoPAJfI8SXjNR/lrxhAmwjLq+9tO0vSRY4JgoNyPl1r1I= X-Received: by 2002:a05:6808:3db:b0:3a1:f2fc:7e13 with SMTP id o27-20020a05680803db00b003a1f2fc7e13mr7233019oie.57.1690137622136; Sun, 23 Jul 2023 11:40:22 -0700 (PDT) MIME-Version: 1.0 References: <102D7169-4730-4E9D-A65D-3B153AB29F51@woofle.net> In-Reply-To: Date: Sun, 23 Jul 2023 11:40:10 -0700 Message-ID: To: Jorg Sowa Cc: Dusk , Marco Pivetta , PHP internals Content-Type: multipart/alternative; boundary="00000000000096cb3306012bd444" Subject: Re: [PHP-DEV] Introducing 2 new modes to round function From: jordan.ledoux@gmail.com (Jordan LeDoux) --00000000000096cb3306012bd444 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jul 21, 2023 at 3:48=E2=80=AFPM Jorg Sowa wro= te: > Thank you for your suggestions. I added two remaining modes and I think > it's complete now. > > I changed the names to `PHP_ROUND_CEILING` and `PHP_ROUND_FLOOR` to be > consisted with rounding modes in number_format() function. I'm not sure > about `PHP_TOWARD_ZERO` and 'PHP_AWAY_FROM_ZERO` as in there it's > `ROUND_DOWN` and `ROUND_UP`, which I also find too vague. > > However, I could find names UP and DOWN in other documentations. And sadl= y > it refers to away from zero and toward zero, so there is big mismatch in > existing naming. > > > https://developer.apple.com/documentation/foundation/numberformatter/roun= dingmode/down > > https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/math/Ro= undingMode.html > I had to deal with this issue when I was doing the rounding modes for my math library in PHP. I ended up providing the following rounding modes: - Half Up (Positive Infinity) - Half Down (Negative Infinity) - Half Even - Half Odd - Half Zero - Half Infinity (Closest) - Half Random (50% chance of either direction) - Half Alternating (Each subsequent call to round alternates rounding direction) - Stochastic (Chance of direction based on proximity... i.e. 1.7 rounds to 2 70% of the time, and rounds to 1 30% of the time) The only reason I used "Half Up" and "Half Down" is because I also used "Half Zero" and "Half Infinity" so it was more clear there were differences. Stochastic is probably the one that sounds weirdest to most people, but is insanely useful for applications like Machine Learning. Jordan --00000000000096cb3306012bd444--