Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123033 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 ACD401A009C for ; Mon, 8 Apr 2024 09:12:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712567600; bh=4NghLSHn0Q2PryuCbXXCWcaN+CgPgxwYo1WMqgdRmFM=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=evzWzHzjU1dU224AQFVusBI6UPqeQw/3lUXS0cXVnhXGm81ebM0C4UivNa933M0nd s8OX6D6v6h7UxMfbe6lQzxrr7FTT7zwD4cPSsfNVYIz/AUz1sC+nHSTRYcMnV3jlCF 6bAaMBwUmgnb+cY/+s6jOCeZZzZ6KGW6vPrnY+GoqDWIS3zi0f32StW4EP5h2dAm0O hr7YDL93Gy9Hl7jmJueADpPU03pVktfy7Lzc7qDhdfvuHW+zYzl/G6hxj9iIK8PhbC oPc2BjWrr8nNFJ2vRNg1lFUKp/jQX33jlhFJzgalrioG6chKfV3YDFUUTTTsTUiyKp jsyj+sMLbXadg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E1FEC1806A4 for ; Mon, 8 Apr 2024 09:13:18 +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 09:13:18 +0000 (UTC) Received: from smtpclient.apple (193.211.49.163.rev.vmobile.jp [163.49.211.193]) (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 078F0401EE; Mon, 8 Apr 2024 18:12:44 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712567564; bh=4NghLSHn0Q2PryuCbXXCWcaN+CgPgxwYo1WMqgdRmFM=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=bDqqnYR6kE/yRcpmeXqpjpKGPiFs7KRdq50KOlHc2GF52MD09orGetPhxZlLJP6/C SwlTKiOTvP3AEEKNjOcRicrJs9hosPZ9T8qcY2erLOxW1W6vXPYkEUIASTwfTi9CBi Qxpy90S4QWprOHWypP5DpZOevsVE82hXgKH70zA4= Content-Type: text/plain; charset=utf-8 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] Proposal: Arbitrary precision native scalar type Date: Mon, 8 Apr 2024 18:12:31 +0900 Message-ID: <50CFC57D-5F50-46B4-92E5-05024BBEEFD0@sakiot.com> References: <1DF4290C-EE0F-49A4-B09F-56DB18327F3A@rwec.co.uk> Cc: internals@lists.php.net In-Reply-To: <1DF4290C-EE0F-49A4-B09F-56DB18327F3A@rwec.co.uk> To: "Rowan Tommins [IMSoP]" X-Mailer: iPhone Mail (21D61) From: saki@sakiot.com (Saki Takamachi) Hi Rowan, > Again, that only seems related to objects because that's what you're used t= o in PHP, and even then you're overlooking an obvious exception: array(1, 2)= Arrays are a bad example here because their contents are themselves values. = For example, it would make sense as an example if the third value in the arr= ay was a flag that controlled the mode in which array_merge operates, but in= reality it is not. > If we ever do want to make decimals a native type, we would need some way t= o initialise a decimal value, since 1.2 will initialise a float. One of the m= ost obvious options is a function-like syntax, decimal(1.2). If we do want n= umbers to carry extra information in each value, it will be no problem at al= l to support that. I don't see any point in "scalar types" that feel almost like objects, becau= se it just feels like you're manipulating objects with procedural functions.= Why not just use objects instead? > On the other side, just because something's easy doesn't mean it's the rig= ht solution. We could make an object which contained a number and an operati= on, and write this: >=20 > $a =3D new NumberOp(42, 'add'); > $b =3D $a->exec(15); > $c =3D $b->withOperation('mul'); > $d =3D $c->exec(2); >=20 > I'm sure you'd agree that would be a bad design. Yeah, I agree that this is a terrible example. But it's easy to come up with= terrible examples like this. Shouldn't you use the original decimal class a= s an example for comparison? > So, again, I urge you to forget about it being easy to stick an extra prop= erty on an object, and think in the abstract: does it make sense to say "thi= s number has a preferred rounding mode", rather than "this operation has a p= referred rounding mode". Sorry, but I have no idea what you mean by "numbers have rounding modes". Nu= mbers are just numbers, and if there's something other than numbers in there= , then to me it's an object. As you can see from the discussion so far, my idea of =E2=80=8B=E2=80=8Bwhat= a native type is and your idea of =E2=80=8B=E2=80=8Bwhat a native type is a= re probably different. At least between the two of us, we may need to first have a discussion about= what the native type should be. Regards. Saki