Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123029 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 519BD1A009C for ; Mon, 8 Apr 2024 00:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712536533; bh=sCof5lb9kRwenSqnVz0zbmxQkvLxN0CGStLqGJ7bUOA=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=QhHjiCsy+1+GN0Ogtp9/o2EVImBv7za0bvFixmVS9JAI9pkR0uxFEIaLZMyO4v+Rx huhPjjxVkNvbV6X7Huf33yZLwQGZ/dK+wg12zDkIKBTMXTfggL2VBr2iZxDz/Td2f6 rAss5Z634tt+X4pExXQjsdKz8uz0ot59J7uiq2Dk6SHKIsT2hN5OGKgM0gD1EURzoO Gdo95VUWqOmVPIW6qeiY65A2swL9tsHVwVeheULmU2J5ZAotdRX4FV2Ch6P3YF5y2K cUDbIxdQXwG9+nYwigp7dcpX0zMPkLe/T2nPaQitq0svl9NFfWYBeyLgGgQ1/v9TAL ykJBOP7GnzwRA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E5900180804 for ; Mon, 8 Apr 2024 00:35:31 +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 ; Mon, 8 Apr 2024 00:35:31 +0000 (UTC) Received: from smtpclient.apple (unknown [117.55.37.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id F3337401D9; Mon, 8 Apr 2024 09:34:57 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712536498; bh=sCof5lb9kRwenSqnVz0zbmxQkvLxN0CGStLqGJ7bUOA=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=nLoe6GNnCUZ6r9/VqwBYP0bPG3RgOW1lTNABwnwnq0lJw/ZDB+bpYh4mqKMbWUjaD VIwuaNfR/3vW/dUOU7E7Ljz5hmAEzJZDqkzy9C/az651GL3bzJ/Imyl+ZG86CwjXkd MQTHOMFyYhtStA25xD9tK4DhBu8egto8BWSNYtWM= Content-Type: text/plain; charset=us-ascii Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6.1.1\)) Subject: Re: [PHP-DEV] Proposal: Arbitrary precision native scalar type In-Reply-To: <002f0cdd-55fe-48b6-87c3-fcc4dd4c9ecd@rwec.co.uk> Date: Mon, 8 Apr 2024 09:34:45 +0900 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <3c74f433-be6b-4f20-beb0-f09db2fb39b6@rwec.co.uk> <494F7C68-81FC-49DE-A292-A782F7C79DB1@sakiot.com> <002f0cdd-55fe-48b6-87c3-fcc4dd4c9ecd@rwec.co.uk> To: "Rowan Tommins [IMSoP]" X-Mailer: Apple Mail (2.3731.700.6.1.1) From: saki@sakiot.com (Saki Takamachi) Hi Rowan > 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: >=20 > $half =3D $whole / 2; > $half =3D numeric_div($whole, 2); > $half =3D $whole->div(2); >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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)? >=20 > My vote is for (a), maybe with (d) as a fallback. There is no difference in how the data is held. Agree. What I'm = referring to is how to initialize the value. If the user has to specify = some parameters, or can specify them as options, that is already the = behavior of the object. I'm making these opinions from an API design perspective. How the data = is held internally is irrelevant. zval has a lot of data other than = values. What I want to say is that if multiple types of parameters are = required for initialization, they may only serve as a substitute for = object for the user. Regards. Saki=