Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122856 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 qa.php.net (Postfix) with ESMTPS id AA4FE1A009C for ; Tue, 2 Apr 2024 13:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712064383; bh=mJ6IlxTU4OxZ//fIoWdpudgyyT9QREG2vHI/PSJxt78=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=lDFK2OOEuZlmxMma5d6OfW/n35zt/uiGAFxcJ2aC173j9/0v7mmSxIYBX8+UCQcp8 4lRvlhDWXP+78rRiK8eLu9F6qxJlqRytpOR2fbowHo7aCYEiB/B7f1r6ejMMj1QUqO G1fLf09bClmXEnuIgT9225xtY0eQefjJM5Ewzd1+WwKsq2y9sveNmGPEQ8XCZl9Rf3 6alv5d9ZUm2j28HnilLoL2VRvS0PqwPJRD7dQ4+yECOqujewRX0PN9Pdycc0VGPC2n dywdXjEClv28c9lWp5777E/5UlTURD6IUSNITFyhyKf5O1dTnHM75myP+T+P0btcaK PsEE4fxYwDMzA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A4A0C18004D for ; Tue, 2 Apr 2024 13:26:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: *** X-Spam-Status: No, score=3.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,SPF_HELO_PASS, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Tue, 2 Apr 2024 13:26:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712064353; bh=mJ6IlxTU4OxZ//fIoWdpudgyyT9QREG2vHI/PSJxt78=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=MciwCDmUliwpTSY5Z1J+R/1iTyCJ7yk0/V0g484CcbslRXiG/9wTwu+hPkGIKY29a eOu8BhYUaINV9pmzyCFqeTcnfJoJqGEojynpI8lhzENco+jwhKl5+6o5a7N+hV7uCA HYghmhKgCP30KfC8NaGlb+sNCw4sd5Z8Bs9B1DFT5yvlKqkuPJ7jmHJynvl7edUyzz G9DippEzS3OCPeS51LV4yM9fpzVu1D020hicEF/pOJvB307weFeb2fvAO0AvERk1jZ qTU29EbN4FHjFfYDJs3V0GojmTSQQqZ74570ee3rLsppDF6N/A8l3l6DfP/Is4S+Gp bPVNeDzv3pfeA== Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 5581510C0D2; Tue, 02 Apr 2024 14:25:53 +0100 (BST) Date: Tue, 2 Apr 2024 14:25:53 +0100 (BST) To: Jordan LeDoux cc: Aleksander Machniak , internals@lists.php.net Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath In-Reply-To: Message-ID: <667254b6-d2f2-271c-2e37-d049957427d5@php.net> References: <4F094EDA-5058-407D-AF39-06FD934FDE1F@sakiot.com> <68CF373E-6ABF-4471-8992-813B4BA1B508@sakiot.com> <904197f4-afb5-401e-9e17-7a655c5449d0@alec.pl> Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-2142553491-1712064353=:14553" From: derick@php.net (Derick Rethans) This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-2142553491-1712064353=:14553 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 29 Mar 2024, Jordan LeDoux wrote: > On Wed, Mar 27, 2024 at 12:08=E2=80=AFAM Aleksander Machniak wrote: >=20 > > On 27.03.2024 01:03, Saki Takamachi wrote: > > >> $num =3D new BcNum('1.23', 2); > > >> $result =3D $num + '1.23456'; > > >> $result->value; // '2.46456' > > >> $result->scale; // ?? > > > > > > In this case, `$result->scale` will be `'5'`. I added this to the=20 > > > RFC. > > > > I'm not sure I like this. Maybe we should be more strict here and=20 > > treat the $scale in constructor (and later withScale()) as the=20 > > actual scale for all operations. > > > > > For addition, it absolutely should expand scale like this, unless the=20 > constructor also defines a default rounding type that is used in that=20 > situation. All numbers, while arbitrary, will be finite, so addition=20 > will always be exact and known based on inputs prior to calculation. >=20 > Treating scale like this isn't more strict, it's confusing. For=20 > instance: >=20 > ``` > $numA =3D new Number('1.23', 2); > $numB =3D new Number('1.23456', 5); >=20 > $expandedScale1 =3D $numA + $numB; // 2.46456 > $expandedScale2 =3D $numB + $numA; // 2.46456 >=20 > $strictScale1 =3D $numA + $numB; // 2.46 assuming truncation > $strictScale2 =3D $numB + $numA; // 2.46456 > ``` >=20 > I ran into this same issue with operand ordering when I was writing my=20 > operator overload RFC. >=20 > There are ways you could do the overload implementation that would get=20 > around this for object + object operations, but it's also=20 > mathematically unsound and probably unexpected for anyone who is going=20 > to the trouble of using an arbitrary precision library. >=20 > Addition and subtraction should automatically use the largest scale=20 > from all operands. Division and multiplication should require a=20 > specified scale. I agree. I think add/subtract also should always take the largest scale=20 here. cheers, Derick --8323329-2142553491-1712064353=:14553--