Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123096 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 35CC91A009C for ; Wed, 10 Apr 2024 16:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712767573; bh=ADyuDngVHNmV7l/2WENhJt76rMIwfR32bHJs7L5XJVw=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=MW+WuiSJZXq2zPkCx0mrl1CsJwLMAMZiEnHxmgZrPoY9M4gXeyTu9v4XWZTsvrc1W Rma5rfZcIDrcphIIJMIG1eLWAN5Op8gJC7X543HPU2NUu0d/BuF1S3qgWdWwdHKvF+ HF1PDlfXz0yC4cWISShPbd7ar8d/SdlgnhX2jyi+8biUve67+IWc1ThaWI+wyS0kGp v8CVn4FrzhhdCpLEnrHlP68JPXIXTbzsKpERCqdIQPELfBIP78uF1pILQijcDpz8iK lsdHnlpurBpKN9PXpVZ4rHUSByvsACW5dAitzVpwJUtmllCf2O1fUV3QjZXX3bDHhB DUg9RqvjxcpaQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1600F1804FE for ; Wed, 10 Apr 2024 16:46:13 +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 16:46:12 +0000 (UTC) Received: from smtpclient.apple (unknown [117.55.37.250]) (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 D95E7401D8; Thu, 11 Apr 2024 01:45:36 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712767536; bh=ADyuDngVHNmV7l/2WENhJt76rMIwfR32bHJs7L5XJVw=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=Gx9sgtw+WuefqYMRDhHjS1eYDgRq85dTl2tPl4CkkPj8PjwXjLsKS10Yi+ARYJfvr dedN/YBXFCglot/Mg7VNabB8CwQeeaSqgi/CXtDBGVeLhtigXYGxu9PecuZnkFmCvT vhBEerQoT96uB8oBZtgJK14YAmO8vvmu2H1xSV2M= 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: Thu, 11 Apr 2024 01:45:23 +0900 Message-ID: References: <15702F55-16D1-43AD-88CC-BC703E267FFC@rwec.co.uk> Cc: internals@lists.php.net In-Reply-To: <15702F55-16D1-43AD-88CC-BC703E267FFC@rwec.co.uk> To: "Rowan Tommins [IMSoP]" X-Mailer: iPhone Mail (21D61) From: saki@sakiot.com (Saki Takamachi) Hi Rowan, > Yes, I agree there's a dilemma there. >=20 > The extra point in favour of TOWARD_ZERO is that it's more efficient, beca= use we don't have to over-calculate and round, just pass scale directly to t= he implementation. Any other option makes for unnecessary extra calculation i= n code like this: >=20 > $total =3D new Number('20'); > $raw_frac =3D $total / 7; > $rounded_frac =3D $raw_frac->round(2, Round::HALF_UP); >=20 > If HALF_UP rounding is the implied default, we have to calculate with scal= e 11 giving 1.42857142857, round to 1.4285714286, then round again to 1.43. >=20 > If truncation / TOWARD_ZERO is the implied default, we only calculate with= scale 10 giving 1.4285714285 and then round once to 1.43. >=20 > (Of course, in this example, the most efficient would be for the user to w= rite $rounded_frac =3D $total->div(7, 2, Round::HALF_UP) but they might have= reasons to keep the division and rounding separate.) Thanks, when I expand on this issue, I'll also mention the pros and cons of b= oth, including the points you mentioned. Regards, Saki=