Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123827 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 4AB391A009C for ; Tue, 25 Jun 2024 16:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719333093; bh=IAf4hFYQ7v6kZwTe3ck41cR6DeEIxAdnFVKDlsqStvw=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=ZKx8EKEF8rLJw8TTgGpy6ohcyW34B5aiAX9YnVZEIOrwpC8fbQ1vpsT9KqkG7WZhA 30jotdBQ8e5AzgW4aNTB8VSxGezw/6HEiFWLZ2w+aHDscEv+cOEO7czFQG9dlbYKGX YHKAYWhEPSPIjQuswshDatjeuWFF64XxtTKLraCBwC+dJAqR2KiA5/JLtgqGhH9kyR PRwQkXS8miMQnJAjrwmbNcv6URqAmzEIrswHA+NUaqQm6jT8GZ/EPyBbu7M+eBTw1Z /OVDCL+tIcgwQf7L+ZIDV3DMc0BjlJ9TBwQcA9QGdtR+3ar5PD8DaPxpKXjlO2yOex 7T4AMB7bUXG6g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AD4D4180874 for ; Tue, 25 Jun 2024 16:31: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: 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 ; Tue, 25 Jun 2024 16:31:31 +0000 (UTC) Received: from smtpclient.apple (47.69.239.49.rev.vmobile.jp [49.239.69.47]) (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 68624401DE; Wed, 26 Jun 2024 01:30:11 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1719333011; bh=IAf4hFYQ7v6kZwTe3ck41cR6DeEIxAdnFVKDlsqStvw=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=v/EZlWIhJNIMZ2geFMONKdscSwQQPQznZotJT5Sm8OjV1n1cLFsDK+1gKL1Ps6puw 0ntudjmZHA6zJaAv8L+fIx3zWrnkVg2w/rKE6Yxacg0sH1Ibt8gGJOz5oWmp/DrGov rjgP0ot3AIaHXi+K3OowyMGaoUizGX7kLyqmVbXU= Content-Type: text/plain; charset=us-ascii 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] Add bcdivmod() to BCMath Date: Wed, 26 Jun 2024 01:29:58 +0900 Message-ID: <0E1E1C82-24A2-46FF-B649-56DD7C39350D@sakiot.com> References: <190502bc4bf.1145fe1df199171.9215746182322416249@barneylaurance.uk> Cc: php internals In-Reply-To: <190502bc4bf.1145fe1df199171.9215746182322416249@barneylaurance.uk> To: Barney Laurance X-Mailer: iPhone Mail (21F90) From: saki@sakiot.com (Saki Takamachi) Thanks all, > My only question is the pseudo-tuple return, which is rarely used in PHP (= although I've used it myself, I think exactly once), and I think this would b= e the first use of it in a built in library. (I may be wrong on that.) I d= on't have a particular alternative to suggest, just flagging that as the mai= n part that could warrant discussion. > It's actually already used by gmp_div_qr(), so +1 from me. I predicted this would probably be on the agenda. Another idea is to pass ar= guments by reference, like in `exec()`. Personally, I find something like a tuple easier to use. However, without ge= nerics, all we know is that the return type is an array, which may be inconv= enient in terms of IDE completion, etc. > I'm wondering whether this needs to be a change to the API, or if it might= be better implemented as a purely internal optimisation to BCMath / Number -= in some way memoize both the quotient and the remainder when either div or m= od is called, and then document for users that calling one after the other w= ill be extremely cheap to run. >=20 > But maybe that brings up too many questions about memory usage - e.g. is t= he memory for this reserved in advance for each instance of Number, or alloc= ated when one of these functions is called, and should it be freed even whil= e the object remains in scope to avoid using lots of memory if many numbers a= re divided or modded. I am considering implementing this not only as a Number class, but also as a= function. Also, it is not practical to record the remainder in the Number object resul= ting from the division. This is because there can be objects whose division r= esults are equal but whose remainders are different. In the discussion of the Number class, it was argued that objects should not= have too much state.=20 Increasing the state of surplus is not desirable in this respect, as it cont= radicts the previous argument. Regards, Saki=