Newsgroups: php.internals,php.internals Path: news.php.net Xref: news.php.net php.internals:124106 php.internals:124107 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 7261F1ADB62 for ; Sun, 30 Jun 2024 15:11:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719760370; bh=2AY2araM5fSRVPxyabzWAMgMWKbCcwUSRPUwQe6i+IA=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=Yzrd3HeQOKqIxeLTQBrZrKLhEiq5Fk736sVdNgP77KALGvEFUnbErXWPisut/xVV3 /TK/Rptzp2MEVl5Iseht4GEUi6bCjGa6PpZ58zEzzvi8md6Se934fRhLqwdEa/zk2R x4PxbEg2Ro5WfRawWt5HYXQNAsc+eMqjmFO3BiSUr2ubktrrsO5OKc10HgYKKyQArR G7OvVLQjd7TwGUh/TbqiHNk0yOf6tVWw8iERjPS2JcVHLmi8bAN2kDFmMYQYSxPl+A Ux1zxQ4sHm31VX2WNuZV1hxG7dpzXcRVFbT5hu/p7m+CI1iSKjuPBlZA0f4WLF1Ixv Kx3c9ZdKOU/uw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1DF55180DC2 for ; Sun, 30 Jun 2024 15:12:48 +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 ; Sun, 30 Jun 2024 15:12:46 +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 088B9401FF; Mon, 1 Jul 2024 00:11:25 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1719760285; bh=2AY2araM5fSRVPxyabzWAMgMWKbCcwUSRPUwQe6i+IA=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=TiCnP61/h3UufnBIcc4l3WHzi43YdOxxOd6a8imGMGU08mx/iK1/TeGiSaTCwig+S XO+U7gYYWthqzEA1nSUF8bwwn3OewGjwiFqH3kTBBEHNNV+7OhVUknEcgNefABGJqR pUdiFTFfc3pgBjiALeNNLYpGjThb30WMws9r67zw= Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: [PHP-DEV] [RFC] [Discussion] Add bcdivmod to BCMath In-Reply-To: Date: Mon, 1 Jul 2024 00:11:13 +0900 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <3B23E039-D90F-4F84-9ECE-C6A9A3E145AF@sakiot.com> References: <668168A7.4040005@adviesenzo.nl> To: Rob Landers X-Mailer: Apple Mail (2.3774.600.62) From: saki@sakiot.com (Saki Takamachi) Hi, >> Just a suggestion: what about making the returned array an = associative >> array ? Like so: >> ``` >> array( >> 'quotient' =3D> 61, >> 'remainder' =3D> 1, >> ); >> ``` >> This would remove the need for devs to remember the order of the = return >> values and would make the return value self-documenting. >=20 > An associative array would combine the worst of an array (no IDE = autocompletion, no strong typing, increased memory usage) with the worst = of an object (no easy way to extract the values into local variables = with array destructuring). >=20 > The example in the RFC doesn't show it, but the following makes the = proposed API really convenient to use: >=20 > $slicesOfPizza =3D new BcMath\Number(8); > $mouthsToFeed =3D new BcMath\Number(3); > [$perMouth, $slicesLeft] =3D $slicesOfPizza->divmod($mouthsToFeed); >=20 > Note how the order of values matches the words in the method name. = First the result of 'div', then the result of 'mod=E2=80=99. Thanks, I have added this example to the RFC (Please let me know if you = have any problems). > I came here to say the same thing. The best solution would be not = having to refer to documentation or experiment with values, and this = hits the nail on the head. >=20 > The only thing that makes it weird is having to write it out, which at = that point, it is probably faster to type out bcdiv and bcmod = separately. >=20 > Have you considered simply using references passed to the function? I = feel like that is more idiomatically php. Of course, that idea was proposed, but it was pointed out that current = PHP tends to avoid such implementations, so we didn't adopt it. The = reason why passing by reference was not adopted was added to the RFC. Regards, Saki=