Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122947 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 6B0871A009C for ; Thu, 4 Apr 2024 21:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712265994; bh=tybY/lg3n5mvl7vv/eCZUj2aRW0sM4Voo0aydSNbZ+c=; h=Date:Subject:To:References:From:In-Reply-To:From; b=KWEAbJVMaRXS89gQFwtHtnQTj2+HwlVOHX3Ko05VKIUXpBikZmKUQfY6HdN61IKSa SAFcq9biXR9dstpyORwyfF7ESNQTxtTUu6K9jgV098yr6h6WtaxMfosHeEq0+uNjWj QOTkS2kc8ZN/6nj+nqjweh3X5DEzaQYuHCATBkeyoJPPH7OrO+mz9+LZfj08+1Z+vI Vg1pQ6O0P+CGX61cZ+aHV5ARlbHdd3mVK2sYDPj3Lf+8n2nQPkqlJ844QR8dfZDXD0 FcLBTbRmIbvWq1MYj/qUBMdICUrIRFqPkspMEVXCQhMZ9xSFlaBgLtTgQYxQxcbQrd imd8cygq+9n/g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8276718056D for ; Thu, 4 Apr 2024 21:26:29 +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 fout5-smtp.messagingengine.com (fout5-smtp.messagingengine.com [103.168.172.148]) (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 ; Thu, 4 Apr 2024 21:26:26 +0000 (UTC) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id B7824138014B for ; Thu, 4 Apr 2024 17:25:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 04 Apr 2024 17:25:56 -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=1712265956; x=1712352356; bh=Gj+CdfY449YLJhUrIF3+Va0l/bKhUGZFeGD+dgkvR+8=; b= TpStzeyUU56R5y7H2JVGyQmmcAsq+tEqQNR5uZ1kJI+aIk/PS71ImwMqANd3Xw6r sCJYyrHRZk38UNTSASHV0CRYDQh1LBg2witNA5E0Cpa1TAlEMQawkHVx4JuKPrti fWpiX1N4lus4Q49y+icuT/mAf3zov9+l+6zaA45c9PfjpZTG9quFwhCF9CjfX23a Or7ntVzHhSPWE7GFtDg8npWsiAfLe4ExAbBzCcbL9Qx4QUY9lBKmVBzFrDnPjKZd wXLKgU8M4NfEMUxH7GpSoYzJiGGq58o+s3Dbi0FHsC1P+0NMvDcSpkcVX7V7ep9K MOjLZq2S8uTl2XUUvwCfgw== 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=1712265956; x= 1712352356; bh=Gj+CdfY449YLJhUrIF3+Va0l/bKhUGZFeGD+dgkvR+8=; b=Q uRBMzL426q313LPrjpewfJT37mankGuYooaIeA4YBHCxj+oZYE78aAnqIKJ1fhPr kv4tgB6rD5+pM+WWxp47lNneK7mQ33hCAjOwpfgyAHFf+96GN2YT6wXAbG0Cq3wM 4Q4EE+Lgt/ILNiIBFt1wVoewo7Wc9l+knhm1IZ6EcI3Mcyqm76woIGZ+54xJmd9o ZDdM/98Q4+rqb0pHrvX4Pd4cWAD+U7A0NabAeruSYcY10GqU0WnGSQFSI8ObPKgH NlXMy1zboZ1CWnBoqZTg0vtMxIp6cTDHZSn6C9WLtJjBH2Z0d8PUtUMmYtxKJ7rb /H+2oAz7sFdk5Az3WmdfQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudefkedgudeivdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth ekredttddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgn fdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnh epffekveduffduvdehjedvfeekleeftddugeefheejudehgeeiudffgeeggeevfeehnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhoph drphhhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 4 Apr 2024 17:25:56 -0400 (EDT) Message-ID: <9dfdd88a-f840-4933-b26b-8149a4381246@rwec.co.uk> Date: Thu, 4 Apr 2024 22:25:51 +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] Proposal: Arbitrary precision native scalar type To: internals@lists.php.net References: <18c42fdbb30.2831.17a3710df6d58f02ca570cc47e197a63@interi.co> Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") On 04/04/2024 02:29, Jordan LeDoux wrote: > But when it comes to fixed-precision values, it should follow rules very > similar to those we discussed in the BCMath thread: > > - Addition and subtraction should return a value that is the largest > scale/precision of any operands in the calculation. > - Division and multiplication should return a value that is the sum of > the scale/precision of any operands + 2 or a default (perhaps > configurable) value if the sum is small, to ensure that rounding occurs > correctly. Near zero, floats have about 12-ish decimal digits of > accuracy, and will return their full accuracy for example. I haven't followed the discussion in the other thread, but I'm not sure what the use case would be for a "fixed scale decimal" that followed those rules. As mentioned before, the use case I've encountered is money calculations, where what people want to fix is the smallest unit of account - e.g. €0.01 for practical currency, or €0.0001 for detailed accounting / trading. If I write $total = 1.03_d2; $perPerson = $total / 2; I want a result of 0.51_d2 or 0.52_d2 - that's why I specified a scale of 2 in the first place. If I want an accurate result of 0.515_d3, I would just specify 1.03_d, since the scale hasn't had any effect on the result. If I want a lossless split into [0.51_d2, 0.52_d2] I still need a function to exist somewhere, whether you spell that $total->split(2), or decimal_split($total, 2), etc. So it seems safer to also have $total->div(2, Round::DOWN) or decimal_div($total, 2, Round::DOWN) and have $total / 2 give an error. Possibly, it could only error if the result doesn't fit in the scale, so that this would be fine: $total = 11.00_d2; $perPerson = $total / 2; assert($perPerson === 5.50_d2) Or possibly, it would just be an error to perform division on a fixed scale decimal, but allowed on a variable-fixed scale decimal. Regards, -- Rowan Tommins [IMSoP]