Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123022 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 0507E1A009C for ; Sun, 7 Apr 2024 18:39:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712515215; bh=kYnHyjPEpZS6WGKRPTMJA2oqYKbWh4sEIhThw3lChbU=; h=Date:Subject:To:References:From:In-Reply-To:From; b=lnetP5kzf+eIUbnr+23CzNM+kPzxd4IdjibLlVIP0LLCsGU3ldpPrpX/ngaQ9awvK vzdRBVrZpeSOOg0jzoNbRyge8C85aDVlMbnQtUX2wcZOfNYK9qK4LAcTarOdyRF07N 88XjJ0hGVRO+fHYPSjoRe44S7u/hLqw7KyyC28IuT2Kgv+E9qdgBlazV8RVrvnNycH wKNUNUg2TbM5hOtIpVQkGFEweR8BBD5IIRXnLvR47mARNpmna/fLTJXUaYj+IN1cqh WpIqsHCw3ZwHzXKxRK4ycWyRrpL5TxngbTm+OMvidcr984vKhBemNk6pRTf507ypKf ycrFJphPenZBA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ACAC3180068 for ; Sun, 7 Apr 2024 18:40:14 +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 fhigh3-smtp.messagingengine.com (fhigh3-smtp.messagingengine.com [103.168.172.154]) (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 18:40:14 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 9786811400A7 for ; Sun, 7 Apr 2024 14:39:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sun, 07 Apr 2024 14:39:42 -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=1712515182; x=1712601582; bh=7obrAC/4akopb/wD2fesK/TCPDKESkcWf2t9CoMMuls=; b= jA1EFSVFrE1OfsPNi9iXcNuNhOZh+mvup7ThtIhJBAk8QeLjMATkhTh/NvDpZXab /AEIeUDolZxcvq9BKfG5MTMABQysshiFbSv7IFunfTS4bABWXmfCB7XcUMeAo9aF dFi1GNUlma8IFoSctQY3wMkUIPG1iBNbJkO961lP94NPMys26H1BDwX4HPt5cKGd 2whop4wtmR2TtA7/hgTtPYOw0DECet0ZZ+aCwSVwHKf1/e+V/keUVRcRUuBMMBE7 0Mq27vv9hIVvMI617TXAa1hWm4/cff3Ddc7mwMI45jRCk0dFBG0bWTlHkPPcSWeA Dll3SeLGWSaq0LjwpVErnw== 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=1712515182; x= 1712601582; bh=7obrAC/4akopb/wD2fesK/TCPDKESkcWf2t9CoMMuls=; b=C pX4e5rA6nKh2hXMK/LKqh8RkPYbfsZiXcHQZA553GqGdDC5PrGKPPWFgng031jpP zno30vk2V2n9QsCnaHdSrwT5YCgLbQuoHZ4C8uPvOzwH4qTot7idF3sVcyjkdIDD GphDO4011s4frn5+sWDQC0guMvaoQk7pxWmlKNGsRy5Qv6DffxqQS3IpVDMBZL7v ZgyWKsSOctAdz6MTMslP3/MBBhO3oVYBLskYrICHpGswwxzwwZSooZTaq7J12+Az /Azg+EujNNFQWC2B1Oz1p4pxxM5AUeBgtBXtskEjlfugrVn2ysI2H/pWVgOOx3qg qsVnoyR309HSyRefRp/Ew== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeggedguddvjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth ejredttddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgn fdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnh epjeekgffhuefggfdtueehgefgudeghfdukeejhfetgeeijeelheevlefhfedvhfdunecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhoph drphhhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sun, 7 Apr 2024 14:39:41 -0400 (EDT) Message-ID: <002f0cdd-55fe-48b6-87c3-fcc4dd4c9ecd@rwec.co.uk> Date: Sun, 7 Apr 2024 19:39:39 +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: <3c74f433-be6b-4f20-beb0-f09db2fb39b6@rwec.co.uk> <494F7C68-81FC-49DE-A292-A782F7C79DB1@sakiot.com> Content-Language: en-GB In-Reply-To: <494F7C68-81FC-49DE-A292-A782F7C79DB1@sakiot.com> 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 14:27, Saki Takamachi wrote: > If we really wanted decimal to be a native type, then the rounding > mode and scale behavior should be completely fixed and not user > selectable. If not, decimal should be implemented as a class. As I replied to Jordan, I don't see why this is connected to "scalar" vs "object" types at all. An object - particularly an immutable one - is just a way of declaring a type, and some syntax for operations on that type. There's really no difference at all between these: $half = $whole / 2; $half = numeric_div($whole, 2); $half = $whole->div(2); In PHP, right now, the last one is only available on objects, but there have been proposals in the past to change that; it's just syntax. For rounding, the first one is the real problem, because there's nowhere to put an extra operand. That problem is the same for a class with an overloaded "/" operator, and a "scalar" type which has a definition of "/" in the engine. Maybe it feels more obvious that an object can carry extra state in private properties, but internal types don't actually need private properties at all. PHP's "array" type has a bunch of different state without being an object (a linked list of items, a hashtable for random access, an iteration pointer, etc); and SimpleXMLElement and DOMNode are exposed in PHP as separate classes, but actually store state in the same C struct provided by libxml2. So I see it just as an API design decision: do we specify the rounding mode of numeric division a) on every operation; b) on every value; c) in a runtime setting (ini_set); d) in a lexically scoped setting (declare)? My vote is for (a), maybe with (d) as a fallback. Regards, -- Rowan Tommins [IMSoP]