Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122920 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 1E4451A009C for ; Thu, 4 Apr 2024 02:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712197915; bh=1YrhnEY1jun6Q84LhPleUdRx3GZjku6E8TfPFZPR9Vk=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=Esn8llFLuoq5tH2jGov6+5T5TW8GXvcukX6TLeHETgykqGgOIfPzlbw+mW/C2KdUn ZnqEYMuthncOdBrxYTCyN+8YdgJF29NJiPW+wnjItMWgYANJORbFDxYYyBmhX3Y7Yq TJBCD7XkqWehyknnyKAfQ1IbMp/g51DUlEtlB1dq582udVNTkkeNbVHO3g7z8LcVzV FPjEEnYhQbSZnZqxIHpvtHcTUUz11G0YhavC+ipQayHAO27jvdrkJBc/TsRpQNOIPN PnUbfRZZvSGypKK0BPHF/eK2CbSgmAgfwbor1esNza0IY6bmLAkfxjXvHZ0ljtHfNa GnUgl8+veaucg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 43C781805EA for ; Thu, 4 Apr 2024 02:31:54 +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 ; Thu, 4 Apr 2024 02:31:53 +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 86A62401D9; Thu, 4 Apr 2024 11:31:21 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712197881; bh=1YrhnEY1jun6Q84LhPleUdRx3GZjku6E8TfPFZPR9Vk=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=i9mLMW0O/PKX6wrPneeGCSE0ONk6vX/4YFI2DbfPye+zNEyPna9W+6srKi7YoJyIT z5mRRYbWVa9CXoUrNAzkN8r+lyRpOcycp3NDxVqDE+Go9on/dFzVS+jjyjR0U6UbXg b7ImfhCeoULineT2rTlQe9/a9qARfAUR4mBYzHbo= 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\)) Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath In-Reply-To: Date: Thu, 4 Apr 2024 11:31:08 +0900 Cc: Lynn , Aleksander Machniak , php internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <4F094EDA-5058-407D-AF39-06FD934FDE1F@sakiot.com> <68CF373E-6ABF-4471-8992-813B4BA1B508@sakiot.com> <904197f4-afb5-401e-9e17-7a655c5449d0@alec.pl> <655FEA80-9AB4-4AAD-A310-70ED968C97A2@sakiot.com> <8FB87901-02D7-4934-9119-55B21CEDDA9D@sakiot.com> To: Jordan LeDoux X-Mailer: Apple Mail (2.3731.700.6) From: saki@sakiot.com (Saki Takamachi) Hi Barney, Jordan, > Right, if a class is not final but has only final methods (including = constructor) and no protected properties then it allows people to extend = it but not break any encapsulation or (I think) impose any more BC = requirements on the maintainer (unless we care about conflicting with = method names of child classes when updating). It lets people just do = something a bit like adding 'extension methods' in C#. I like it. People = could write e.g. `$bcChildNumber->isPrime()` instead of = `BcNumberUtils::isPrime($bcNumber)` > Yeah, I suspect the most common child class will be something like = "Money" that additionally has a parameter denoting what currency the = value is in, since that is by far the most common use case for arbitrary = precision math in PHP. Making the calculation methods final should do = fine in my opinion. I realize that the purpose of using final here is to prevent users from = customizing the behavior of operator overloads. In the RFC, there are = methods that do not involve operator overloading, such as `round`, but = do you think these should also be made final? Or should only methods = related to overloading be made final? IMHO, there are methods such as `powmod` that are computational = functions but are not related to operator overloading, and from the = viewpoint of consistency, we believe that all methods should be made = final without exception. > I think that having it be an optional part of the constructor and = having a method to modify it is probably sufficient to help with = operator overloads. Importantly, it still needs to take that setting and = use it intelligently depending on the operation as we've discussed, but = that should cover the use cases I was imagining. >=20 > The exact behavior should be very clearly documented and explained = though, as this is a different way of interacting with BCMath than the = functions. It's better I think, because it takes advantage of the fact = that this will be state-aware, which the functions aren't, and is one of = the largest benefits of using objects. >=20 > Also, to address an earlier question you had Saki, the term used = should be "scale". Scale is the total number of digits to the right of = the decimal point. Precision is the total number of significant digits. = The BCMath C library works on scale, I believe, so that should carry = over here. Most other arbitrary precision libraries in C use precision. Thanks, I agree with you that it works a little differently than the = existing BCMath function, so it needs to be well-documented. I have summarized the discussion so far, made some corrections, and = updated the RFC. I would be happy if you could check it out. Regards. Saki