Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123323 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 3058A1A009C for ; Thu, 16 May 2024 13:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1715867674; bh=Ny0aWNvF0e3pIDzfB2RqTIa+hkwOneIoAho9UY9gGm4=; h=From:Subject:Date:Cc:To:From; b=k+jLrjU0pBxvWr1jopdzzv8rRWSiDbnZghAFD6OnxquH3lg2zgxiyQjX9APiV2HhX UqQKIkpBZUxy+1izshnCPu/jd0tYvBtmcuNS/1Oa9THDvk8N3iCVDiWBrujkMOkfcR oMg3NmdOiek0QvhrkY39YPaw9AbcFQa3GGToK2ukhaXMPepotkUXGL5vlZ+nmSVfRY ISbqZ4g0F+2srld8lakAqv+k2DEOtbJCOzo23RLBe2tk5lS7GQZ7qbuJ0RkelrwzOJ QJj+Cb/gCjaVRofAjULhG2Q8/kO+fKZM0al6f3tg694YTaSfCxOgxAqCGvceRPO6rK xUF/93wjzGPGg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3954D180056 for ; Thu, 16 May 2024 13:54:34 +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: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) 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 ; Thu, 16 May 2024 13:54:33 +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 F41AF401D3; Thu, 16 May 2024 22:53:38 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1715867619; bh=Ny0aWNvF0e3pIDzfB2RqTIa+hkwOneIoAho9UY9gGm4=; h=From:Subject:Date:Cc:To:From; b=w/axl9zmA0w808FxafscPjGGOO1ExNcESZqLuT6QsPNB83YIqi/QrBzT+JVvHgm6G wcMAT8qx8nWd4l5cWmDD3rbXyblB5Ylda0AIOsJEMZx0w/xqqqfp8TmO21qu6FD8tL xB224a7HmBYpR06k/Tlayi0xBFeywhgxwtEzfgRQ= 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 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: [PHP-DEV] [Discussion] Follow-up RFC for BCMath\Number object Message-ID: <1D8D71FE-20DC-40E4-BEA5-4B438B8BC825@sakiot.com> Date: Thu, 16 May 2024 22:53:26 +0900 Cc: "Gina P. Banyard" , =?utf-8?Q?Tim_D=C3=BCsterhus?= To: php internals X-Mailer: Apple Mail (2.3774.500.171.1.1) From: saki@sakiot.com (Saki Takamachi) Hi all, I would like to start additional discussion about BCMath\Number in this = thread. If my summary is incorrect, please let me know. First, make a list of points to note.=20 - Suggestions for using 64-bit integer types internally for performance > If we are not going to use the newfound opaque type to introduce = performance optimization for the common cases of small numbers that fit = into 64-bit integers, then the value of adding a dedicated object is = vastly diminished. > Python is *literally* doing this sort of optimizations to improve the = speed of their arbitrary precision integer type for the common use case = of "small integers". >=20 > In general, if it cannot fit in a native type then it should continue = to use a string, but I would expect the *vast* majority of cases to fit = in a 64-bit integer. IMHO: I agree that it can be computed fairly quickly if the conditions = are right. However, I believe that this itself does not require an RFC = and can be addressed as part of a performance improvement. - Points out regarding naming, such as changing "powmod" to =E2=80=9CpowMo= d=E2=80=9D IMHO: I simply copied the existing naming, so I have no objection to = using the correct naming conventions. - Points out regarding comparison methods > In general, I am not sure why there is a need in the first place to = expose any of the overloaded operators as methods. > This includes the add/sub/div/mult/mod methods, but I can be convinced = that this makes some sense. >=20 > I was planning on tackling our rather broken comparison semantics [1] = this year, but got distracted by the broken container/offset semantics = instead. [2] > As, IMHO, we need to fix the internal object handlers and semantics = first before giving this power to userland. > And I feel strongly that using instance methods for overload is the = "wrong" way of doing it. > Moreover, if we do provide the option for userland to overload they = should, again IMHO, *just* be able to overload =3D=3D and <=3D>, not all = the individual comparison operators. > Thus, providing all those methods makes no sense to me. >=20 > Moreover, taking inspiration from userland for naming methods because = they *cannot* overload operators seems backwards. > Userland classes, if they want to provide such functionality, *must* = implement a wide range of methods, however an internal class does is not = required to do this. > Therefore, I am not really convinced by following suit on userland = nomenclature. IMHO: Indeed, as long as have compare, all the functions of the = comparison method can be fulfilled. This is related to "Methods to be = published" described later. These are exactly the I don't know if I'll = use it, but I added it because it seemed useful'' method. Certainly, = there are no things we can't do without these methods. > However, I see no reason for exposing lt/gt/gte/lte. > I am also not really a fan of the compare and equal methods to be = instance methods compared to static methods. > Adding those methods might interfere with any potential RFC that adds = an Equatable/Ordable interface to allow userland classes to overload the = comparison operators. I think this is a type of functionality called =E2=80=9Cprocedural". - Whether existing BCMath functions should accept BCMath\Number IMHO: As Derick also mentioned, scale is handled differently, which can = lead to confusion. - About the behavior when casting BCMath\Number to bool IMHO: I like it like int where 0 is false and everything else is true. - Regarding whether the method you plan to publish is really necessary Note: For example, the format() method only supports the notation = methods of a limited number of countries, so its functionality is = incomplete. In addition, it has been pointed out that it would be better = not to expose many functions from the beginning, but to keep them to the = minimum necessary first, and add some methods later. IMHO: Admittedly, I may have crammed in too many features to make it = useful. Which method do you think is the minimum required? Regard, Saki=