Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123826 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 55BC11A009C for ; Tue, 25 Jun 2024 16:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719332065; bh=KJdZ0ftbLGOw9DXJQhzox/ontje84vsyzR/c9hrcB4o=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=RkMqI43HW96kE6+0uY01JMIN4YjRGomVlu9Prgi6jDc3jKHrfduwHWfmO8SKAQDoR cAHYomH6wWBIhZ6LDv3KnfKDEOZ/sdV/hdBCL6gFyqNpiX5L/HCPquW+hHbz42b+x6 YXkjx5MUgE6/BFuFkS7mOh76WNqkmDvRO5LUKeW28BDK3ZgDwRkFkS11JbYpVR4lAp QmXkHEl5WFQsFwOQ7wCUHn14xASXkrdFRdRmogCbLfddqTD+uAnaDplNBjZPHhGHl+ +nEZWBKEw+8Zu/o29FHsxfIyF1OyR6Hgwg5+wJnQLYfXQXnnyNotigyxt2RGLpntp2 tEoxAISymCH0A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E66761808FA for ; Tue, 25 Jun 2024 16:14:20 +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=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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 sender21-op-o13.zoho.eu (sender21-op-o13.zoho.eu [185.172.199.227]) (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:14:19 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1719331966; cv=none; d=zohomail.eu; s=zohoarc; b=LixUO6tj9Nfh3h3jMgfX0Xg/NxdtcCEtDLdZuBGwcCySHU9zUzdzfMpyFziF9z+0IbXcozQEdBOzQuoIS1cWiBq/odqOLT39gKnl3qsn/hr5ksio13gCO1hYTdLGq/0yzVVW22EeQ7HO5mHfY8ExtQdNmX5vBnUGQ+f4E8suRgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1719331966; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=iYxkbFta4T3igticCoSjZFLd8TjVZS0QkcWKPE2Yavs=; b=iFhhLFoMdupjzXEfalAD7MDtym9bMWSxpA8H7N0LNN6mo3Bn0oXkiVV7kc8Mn5UWx0JkTSwfU7rEZkckRrM/awiPOUIvsa7vRmAcrbCVF+S02BJEDm2AO48Kh58ioXRYqCqUywq5LpK+wOehDoDx5ut2DpQR2tAAw8dwMU7n0cE= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=barneylaurance.uk; spf=pass smtp.mailfrom=barney@barneylaurance.uk; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1719331966; s=zmail; d=barneylaurance.uk; i=barney@barneylaurance.uk; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=iYxkbFta4T3igticCoSjZFLd8TjVZS0QkcWKPE2Yavs=; b=BGi9nO0Z08OiWSpSp6R7PBgNUydDBWvjH3eQuPkV1XS570I0KRApam2j5QNULUA+ pQuCwhxG1SFsssn1YqxtPmRaW78pp1LykxmZm+HXrrvkJLdIYKHEnN7zMdpibcljWzx 0e3661pgnQJaBAQ6cjtQksL3hPHTd+2UuXEcn+oU= Received: from mail.zoho.eu by mx.zoho.eu with SMTP id 1719331964134862.401786732287; Tue, 25 Jun 2024 18:12:44 +0200 (CEST) Date: Tue, 25 Jun 2024 17:12:44 +0100 To: "Saki Takamachi" Cc: "php internals" Message-ID: <190502bc4bf.1145fe1df199171.9215746182322416249@barneylaurance.uk> In-Reply-To: <90AAEBAA-30DC-40B4-AEBD-D4958753324A@sakiot.com> References: <90AAEBAA-30DC-40B4-AEBD-D4958753324A@sakiot.com> Subject: Re: [PHP-DEV] Add bcdivmod() to BCMath Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail From: barney@barneylaurance.uk (Barney Laurance) ---- On Tue, 25 Jun 2024 10:11:10 +0100 Saki Takamachi wrote --- > Hi internals, > > I've been working on improving performance of BCMath lately, and I found that I can get the div and mod in one calculation. This is obviously faster than calculating it twice separately. > > Do you think there's a demand for this feature? > > e.g. > ``` > [$quot, $rem] = bcdivmod('123', '2'); > // $quot is '61', $rem is '1' > ``` > > The naming and return value scheme is inspired by Python and Ruby. > > Of course, if this is added, equivalent functionality will be added to the Number class. 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 mod is called, and then document for users that calling one after the other will be extremely cheap to run. But maybe that brings up too many questions about memory usage - e.g. is the memory for this reserved in advance for each instance of Number, or allocated when one of these functions is called, and should it be freed even while the object remains in scope to avoid using lots of memory if many numbers are divided or modded.