Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123822 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 2C21F1A009C for ; Tue, 25 Jun 2024 15:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719330852; bh=wRvlZq1gRZiW8mj+vTDE22n5mjAzd5jZzM/ZZ2i8QHs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=BOgNZ62S/tBNPik9zlIVkhyUVSIHehCs9HUwg/lMQ1yWvv0wvAa1E2Vzj1CqbEUsh SUL0PkvqcynMNUI4KcQoAccMqqwtXeND/YdoqNF8EeOgLu477PbC/7FybuSc2y0uRR sOeG7cNOeRf78He0vb2sD1w45O+D2ILyWEZVw4C5wOCE4RexsoRYTnMaTbQ7Cp89FT lupV4OtLwOpwikir310squvy1CMBDRvrmICKSE4QJhw+QdTXYJ6jnFws04WISaONFn h/cil1F+XZBsIpO5CMXuG1HFnkQvORSpkozy/MhBDwkYxufH4qcINue5Wm88X6El0c XkYcnBslOjurw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 660F81805B1 for ; Tue, 25 Jun 2024 15:54:10 +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,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) (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 15:54:05 +0000 (UTC) Received: by mail-il1-f174.google.com with SMTP id e9e14a558f8ab-37613975e20so22414445ab.2 for ; Tue, 25 Jun 2024 08:52:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719330767; x=1719935567; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=2+HNIGlp7AwC9rf72dr589SpfmKqdhbLuL6gbdN+Z+0=; b=i40FFTMKW+v6dBARr7KDvI0a4eVp+lSp/obvox4IPxl72+q0d00x1fMVyZ7AgQtxW0 e2PnNXgf097cRlHwtoblxHH2Su6gngSKKQczkNAqq8aI0WVMm7vNpH6Y2FyCwMw3Nnki 0XjMqVAvKh/vENQUYspTtBsaYPP1qdDokQgMT4iZUUVWN3Z10nPnWE0CXqywAD/zfCBR 9pn6ptZIy1aR6mEgcFUwxEcDOJLRC5ZJJAoSvjnk+qCDRPxEfte6XHjjyCppGr9bUL3R JwDGwsTpUWLqSh0lrXoyrMqCMi/TX0DM3ZYfcUeERfmMjTsVCtnAJk4vmSmttDcSJotJ NRyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719330767; x=1719935567; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2+HNIGlp7AwC9rf72dr589SpfmKqdhbLuL6gbdN+Z+0=; b=i3+646q9UMwR8msnado2DbMMkTnh9EI2x13HUpU7BiyKUALSsycg5r0SIa3gz2PJqt Nm+Rk0F6MUlFp3V7zS09uzQe1cTfuaD4nx7FFZWmP0VJLU2KvGHtY0lI3r8jtiMObqeh QKd04RgOUumJPkJ5i7Lp6vzXwzLFaYXV9jHgZ5z2k4HG3IhJkWg5bC3+NC4jgA69xhsu /xVpA9N2xavR4mPWIPIZR7aNLyRzaANCJPYTDcM5epGrMQpPl+YJZf0sJ6hGLQY3CWM1 80+ZqhFMnGgQp/z0pEwjQLT81vBXZZA9w8olXQX+iEhwLDi9Kaqt+HFTRyzrhLN2tHu1 0Ttg== X-Gm-Message-State: AOJu0YzAOFv2kqrj6ynrFKzTvmPi5J6nwD5r7SEXgx5VOUQ+osu52aHg rfAEaSMhhkbOEVLGGYByzUnM9GumgIsbUA75ps4na+7uGZtiGowivvYgrDqUqRrKBb4apuL4Qjd ok5Az1z/4JlWrfNRIKMj9io8whdjOvVsD X-Google-Smtp-Source: AGHT+IHTldd4QXoYUilOrhKIiTCW0ERlQkTJOmfzG/kFQogBAjx1ugvw1kuf20KJW9JrpXELhl5ta1P3mflPiucOhjs= X-Received: by 2002:a05:6e02:b4b:b0:375:9422:a045 with SMTP id e9e14a558f8ab-3763f6c214amr95168625ab.30.1719330767347; Tue, 25 Jun 2024 08:52:47 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <90AAEBAA-30DC-40B4-AEBD-D4958753324A@sakiot.com> In-Reply-To: Date: Tue, 25 Jun 2024 17:52:14 +0200 Message-ID: Subject: Re: [PHP-DEV] Add bcdivmod() to BCMath To: Larry Garfield , Saki Takamachi Cc: php internals Content-Type: multipart/alternative; boundary="000000000000a3aa36061bb8e39c" From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000a3aa36061bb8e39c Content-Type: text/plain; charset="UTF-8" Hi, 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. > > Regards, > > Saki > I would definitely use this in brick/math: https://github.com/brick/math/blob/0.12.1/src/Internal/Calculator/BcMathCalculator.php#L43-L49 > This isn't something I'm likely to ever use as I don't do complex math > much, but it seems like a reasonable optimization for those that do. No > objection. > > 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 be the first use of it in a built in library. (I may be wrong on > that.) I don't have a particular alternative to suggest, just flagging > that as the main part that could warrant discussion. > > --Larry Garfield > It's actually already used by gmp_div_qr(), so +1 from me. - Benjamin --000000000000a3aa36061bb8e39c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

I've been working on im= proving performance of BCMath lately, and I found that I can get the div an= d mod in one calculation. This is obviously faster than calculating it twic= e separately.

Do you think there's a demand for this feature?
e.g.
```
[$quot, $rem] =3D bcdivmod('123', '2');=
// $quot is '61', $rem is '1'
```

The naming = and return value scheme is inspired by Python and Ruby.

Of course, i= f this is added, equivalent functionality will be added to the Number class= .

Regards,

Saki

I would d= efinitely use this in brick/math:

=C2=A0
This isn't something I'm likely to ever use as I don't do compl= ex math much, but it seems like a reasonable optimization for those that do= .=C2=A0 No objection.

My only question is the pseudo-tuple return, which is rarely used in PHP (a= lthough I've used it myself, I think exactly once), and I think this wo= uld be the first use of it in a built in library.=C2=A0 (I may be wrong on = that.)=C2=A0 I don't have a particular alternative to suggest, just fla= gging that as the main part that could warrant discussion.

--Larry Garfield

It's actually alre= ady used by=C2=A0gmp_div_qr(), so=C2=A0+1 from me.

- Benjamin
=C2=A0
--000000000000a3aa36061bb8e39c--