Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123025 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 DBA7E1A009C for ; Sun, 7 Apr 2024 21:44:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712526291; bh=3svTknN6SDvkRJd7tODa6x5JMiE3N+44zrCjCTmjDD8=; h=Date:Subject:To:References:From:In-Reply-To:From; b=hENBmYGMSpjGjdAL3sqrpA4S6VZkO4BKFFH0q3DyLq3VMovrnCfSuBT+Ca98D6aDE 6/Gb3zE8gzHc7PiOEzLbnQMjkXE5MXsdVbyhUHuWuBzN6Z7cix32NLKo/l1rbnODSf sz4wRur+RV3n9ChzmP6wqKxQOpoOiOEryoMLn7WxmFXYJ88vWA9Rx2zktUN4MyZEF4 8CgqUK22Tu+rksk9abim4IvoPokj/vHoB20jWuInf6QN2CZwha4vyI2V1ajhoUrjXs x0aKzxHgEyrR6kyjmcNsUa1WnCDsllQbMg8Lxb5dSLFXwTnH0TFr1KYbPpCbwWVKGE njjDP9PKk5kgw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 94FED180079 for ; Sun, 7 Apr 2024 21:44:49 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, 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 fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 ; Sun, 7 Apr 2024 21:44:48 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id 4C7B31380083 for ; Sun, 7 Apr 2024 17:44:17 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 07 Apr 2024 17:44:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1712526257; x=1712612657; bh=xQKTvxMJkRjfpRT/8LYLaDOg9CPeRXpvUPSbWSz5ITI=; b= NDNACjXCn6eKNA4HU5jpqRqWs4XJRJSmzHWpliC3E/4QTZ4tbqMwcXRuMXOsmg3Z hIpc9Xx2+8la78bJSpGTM6wRtyVhLW/2NBjJ17Bu/KjoXc3K3eX8iZ2fEbYEZltF j8yH3GPdE04SYZUIHLfcYDS+qXZd11Kqu8WRn4eG4Q8CyHQPUfxiORDcKAox5uub pDd/5ly+yED8vEXpcgPE2e2sd7XGQwCXoGaGdgS9p5Z+JG6V1gbb1CQMUgHVnErV 07u6H3UvVZc957360Ixoyxmp7bZIGP2MVW1H5s7Yw+jOFPRr01rR8UvBSXH9xh+Z 4bH11MNhoKxfxeAXseBIbw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1712526257; x= 1712612657; bh=xQKTvxMJkRjfpRT/8LYLaDOg9CPeRXpvUPSbWSz5ITI=; b=M 2R9uObOabxlabLLQLWSLIhwaplHPmFYcpRn6AAidc99UXGZfer5ucqYpLayjpjvF 8QxrH0OHGxt/k+m7Z86h1WRCmt/OUSZmqQ+zlKP6c+/Hh70eOA0ykuxyT4sZC0tf zW+KBsvAyIvzZWnKfwvCT5paGQU4/IQIa1WhH+acvbAvpkeFXC+vfspFJBAnM4TX GBoaxmwlDtrmf7Z4wWQNa4NWbXVe0SEamGOwAB365r48HPUNNTE+LtGh2kQKrU5/ 83yDt/O7ZFeHZ56v903rDqREnWPhV9IeKWKmGBGTa0UIrqayYbGlCs7uA9O4Bf2W pm9x9WjqBCOpg7JtKffrA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeghedgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtje ertddtvdejnecuhfhrohhmpedftfhofigrnhcuvfhomhhmihhnshculgfkoffuohfrngdf uceoihhmshhophdrphhhphesrhifvggtrdgtohdruhhkqeenucggtffrrghtthgvrhhnpe ejkefghfeugffgtdeuheeggfdugefhudekjefhteegieejleehveelhfefvdfhudenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehimhhsohhprd hphhhpsehrfigvtgdrtghordhukh X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 7 Apr 2024 17:44:16 -0400 (EDT) Message-ID: <0f3d0f89-3064-4d56-9fb2-801bb0cda8a5@rwec.co.uk> Date: Sun, 7 Apr 2024 22:44:14 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Native decimal scalar support and object types in BcMath - do we want both? To: internals@lists.php.net References: <40553F28-2EC2-475A-BD8E-1D6517AA2A51@rwec.co.uk> <2B518F62-B774-45C9-82A2-EF6653AAE34E@sakiot.com> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 07/04/2024 20:55, Jordan LeDoux wrote: > I have been doing small bits of work, research, and investigation into > an MPDec or MPFR implementation for years, and I'm likely to continue > doing my research on that regardless of whatever is discussed in this > thread. I absolutely encourage you to do that. What I'm hoping is that you can share some of what you already know now, so that while we're discussing BCMath\Number, we can think ahead a bit to what other similar APIs we might build in the future. The below seems to be exactly that. > Yes. BCMath uses fixed-scale, all the other libraries use > fixed-precision. That is, the other libraries use a fixed number of > significant digits, while BCMath uses a fixed number of digits after > the decimal point. That seems like a significant difference indeed, and one that is potentially far more important than whether we build an OO wrapper or a "scalar" one. > So, for instance, it would not actually be possible without manual > rounding in the PHP implementation to force exactly 2 decimal digits > of accuracy in the result and no more with MPDec. The current BCMath proposal is to mostly choose the scale calculations automatically, and to give precise control of rounding. Neither of those are implemented in libbcmath, which requires an explicit scale, and simply truncates the result at that point. That's why I said that the proposal isn't really about "an OO wrapper for BCMath" any more, it's a fairly generic Number API, with libbcmath as the back-end which we currently have available. So thinking about what other back-ends we might build with the same or similar wrappers is useful and relevant. > The idea of money, for instance, wanting exactly two digits would > require the implementation to round, because something like 0.00000013 > has two digits of *precision*, which is what MPDec uses, but it has 8 > digits of scale which is what BCMath uses. This brings us back to what the use cases are we're trying to cover with these wrappers. The example of fixed-scale money is not just a small niche that I happen to know about: brick/money has 16k stars on GitHub, and 18 million installs on Packagist; moneyphp/money has 4.5k stars and 45 million installs; one has implementations based on plain PHP, GMP, and BCMath; the other has a hard dependency on BCMath. Presumably, there are other use cases where working with precision rather than scale is essential, maybe just as popular (or that could be just as popular, if they could be implemented better). In which case, should we be designing a NumberInterface that provides both, with BCMath having a custom (and maybe slow) implementation for round-to-precision, and MPDec/MPFR having a custom (and maybe slow) implementation for round-to-scale? Or, should we abandon the idea of having one preferred number-handling API (whether that's NumberInterface or a core decimal type), because no implementation could handle both use cases? Regards, -- Rowan Tommins [IMSoP]