Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123085 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 C6EF51A009C for ; Wed, 10 Apr 2024 09:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712741973; bh=KYyG4amJwcvhXG/FMgb1zt8C1aB8spDP9U7GMdEfJtg=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=ea8mMWrp6D0JlPuVg2BchQ+j+l5vTb5f8FLt/beA29aC70zquDJ7Tj101bXYTFcKQ JcsnguuEoLVeNBz4W/La8+ZG84yFSKbrq+HR7hKHh87iNWg5vsNxZVuOE4b3sr/YC3 MZA9oFm9Fth5LwaNb1Yj72UBsBeDUM2p/Ar7/26e07zxgpU53chKl6x7Jzl5e+t7hd OIkSsH5tDr+W/wYsTAe5K4UrArvDel6c7rsEXXd63eKJwKz9I1lMGxna046fYiX7Ac NTX7jFsqRBQsJxpEqpolOdoNRkEJCHiLEMc/ys6b1e3CLrXD4Ett9pp2OJ8DzryaaH sS2Qcj6QsOs2A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 530BC18003E for ; Wed, 10 Apr 2024 09:39:32 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail.sakiot.com (mail.sakiot.com [160.16.227.216]) (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 ; Wed, 10 Apr 2024 09:39:31 +0000 (UTC) Received: from smtpclient.apple (24.12.156.220.rev.vmobile.jp [220.156.12.24]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id 6537B4011E; Wed, 10 Apr 2024 18:38:56 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712741936; bh=KYyG4amJwcvhXG/FMgb1zt8C1aB8spDP9U7GMdEfJtg=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=Xpf7MJxS6Xi4uE/ijmimUdjOUSuqU4i4l0q9U4UETaV+qUXJxUTeB7SJeQIq/Fesf nvSfQucuCWuFYYx8Vfl05RnnlG56I6T/jJ4Qg7qZz6lufIdleopEBeHY0o4QzgjJXE HTQoVAMezc4SMeOAJxuN78pEikJ13DSPMS8KQaK4= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath Date: Wed, 10 Apr 2024 18:38:44 +0900 Message-ID: <04F88690-82B6-4441-B155-C489EACD6DC5@sakiot.com> References: Cc: internals@lists.php.net In-Reply-To: To: "Rowan Tommins [IMSoP]" X-Mailer: iPhone Mail (21D61) From: saki@sakiot.com (Saki Takamachi) Hi Rowan, > That's why I mentioned the two different groups of users. The scale and ro= unding mode aren't there for group (a), who just want the scale to be manage= d automatically; they are there for group (b), who want to guarantee a parti= cular result has a particular scale. The result of $a->add($b, 2, Round::HAL= F_UP) will always be the same as $a->add($b)->round(Round::HALF_UP) but is m= ore convenient, and in some cases more efficient, since it doesn't calculate= unnecessary digits. >=20 > Remember also the title and original aim of the RFC: add object support to= BCMath. The scale parameter is already there on the existing functions (bca= dd, bcmul, etc), so removing it on the object version would be surprising. T= he rounding mode is a new feature, but there doesn't seem a good reason not t= o include it everywhere as well. Ah, I understand. There may certainly be use cases where demand specifies a s= cale smaller than the maximum scale in order to save computational costs. Th= at makes sense to me. Also, considering the two groups you presented, the group that wants to cont= rol the scale is probably not going to use operator calculations, even thoug= h they could provide various options in the constructor. Unless look at the c= ontents of objects in the calculation process using var_dump or something, c= an't understand the state just by looking at the code, which can lead to bug= s. They probably don't like that kind of code. > Again, the aim was to match the functionality of the existing functions. I= t's likely that users will migrate code written using bcdiv() to use BCMath\= Number->div() and expect it to work the same, at least when specifying a sca= le. Having it behave differently by rounding up the last digit by default se= ems like a bad idea. >=20 > Thinking about the implementation, the truncation behaviour also makes sen= se: the library isn't actually rounding anything, it's calculating digit by d= igit, and stopping when it reaches the requested scale. >=20 > The whole concept of rounding is something that we are adding, presumably b= y passing $scale+1 to the underlying library functions. It's a nice feature t= o add, but not one that should be on by default, given we're not writing the= extension from scratch. I was thinking about this today, and I think both are correct opinions on wh= ether to set the initial value to HALF_UP or TOWARD_ZERO. It's just a matter= of prioritizing whether consistency with existing behavior or consistency w= ithin a class, and they can never be met simultaneously. Therefore, I am considering adding a more detailed explanation to the RFC on= this issue and taking a second vote to decide. Regards. Saki=