You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C++][Compute] Add quotient and modulo kernels #28497
quotient (result after division, discarding any fractional part, a.k.a integer division)
mod or modulo (remainder after division, a.k.a % / %% / modulus).
The returned array should have the same data type as the input arrays or promote to an appropriate type to avoid loss of precision if the input types differ.
yibocai#1:
I agree "divmod" to return quotient and remainder at once is more efficient.
x86 idiv instruction always returns quotient together with remainder. In computation cost, div = mod = divmod.
Arm sdiv instruction does division only. So div < mod = divmod. We can use the existing "division" kernel if we only want the quotient. https://godbolt.org/z/fvGh3vh3f
Apache Arrow JIRA Bot:
This issue was last updated over 90 days ago, which may be an indication it is no longer being actively worked. To better reflect the current state, the issue is being unassigned per project policy. Please feel free to re-take assignment of the issue if it is being actively worked, or if you plan to start that work soon.
Dr. Jan-Philip Gehrcke:
Bonjour! I wanted to use the modulo operator today in a filter expression in a scanner. Antoine and Jacob pointed me here. #11116 has stalled a bit seemingly. If I can, I would love to help land that.
Eduardo Ponce / @edponce:
Hi, [~jgehrcke]! I will be glad to share with you this PR and what is missing to get it over the finish line. As I understand this PR is mostly complete, but it requires to be fully rebased (I did some minor updates a few minutes ago) and we need to add more unit tests.
A modulo kernel would also be nice for duration types (which are just integers under the hood). For instance, in time series a common task is autodetect the frequency at which time stamps are provided, which can be done by computing the GCD of all time deltas.
This issue has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this issue will be closed in 14 days. If this improvement is still desired but has no current owner, please add the 'Status: needs champion' label.
✏️ Note, there's further-reviews-welcome related PR #48914 (issue #46901) which would add single-result remainder (truncated) and modulo (floored) kernels.
This issue should remain open for quotient and combined-kernel work. Might be trunc_divmod ≡ [trunc_quotient, remainder] floor_divmod ≡ [floor_quotient, modulo]
per
Activity
asfimport commentedon Jun 10, 2021
Antoine Pitrou / @pitrou:
Perhaps this could be a single "divmod" kernel if that makes the computation more efficient?
(note "divmod" is the Python name for that functionality)
Should also choose what happens for negative divisors.
asfimport commentedon Jul 29, 2021
yibocai#1:
For the record,
libdividemay be useful for optimal integer division performance.https://github.com/ridiculousfish/libdivide
NOTE: this is only for
vector/scalar, when there's only one divisor.asfimport commentedon Jul 29, 2021
yibocai#1:
I agree "divmod" to return quotient and remainder at once is more efficient.
x86
idivinstruction always returns quotient together with remainder. In computation cost, div = mod = divmod.Arm
sdivinstruction does division only. So div < mod = divmod. We can use the existing "division" kernel if we only want the quotient.https://godbolt.org/z/fvGh3vh3f
asfimport commentedon Jul 29, 2021
Eduardo Ponce / @edponce:
@cyb70289 thanks for the tips!
asfimport commentedon Jan 14, 2022
Krisztian Szucs / @kszucs:
Since the PR is in draft, I'm postponing to 8.0
asfimport commentedon Oct 13, 2022
Apache Arrow JIRA Bot:
This issue was last updated over 90 days ago, which may be an indication it is no longer being actively worked. To better reflect the current state, the issue is being unassigned per project policy. Please feel free to re-take assignment of the issue if it is being actively worked, or if you plan to start that work soon.
asfimport commentedon Dec 15, 2022
Dr. Jan-Philip Gehrcke:
Bonjour! I wanted to use the modulo operator today in a filter expression in a scanner. Antoine and Jacob pointed me here. #11116 has stalled a bit seemingly. If I can, I would love to help land that.
asfimport commentedon Dec 15, 2022
Eduardo Ponce / @edponce:
Hi,
[~jgehrcke]! I will be glad to share with you this PR and what is missing to get it over the finish line. As I understand this PR is mostly complete, but it requires to be fully rebased (I did some minor updates a few minutes ago) and we need to add more unit tests.randolf-scholz commentedon Apr 24, 2024
A modulo kernel would also be nice for
durationtypes (which are just integers under the hood). For instance, in time series a common task is autodetect the frequency at which time stamps are provided, which can be done by computing the GCD of all time deltas.kou commentedon Jun 25, 2025
Related discussion:
[DISCUSSION][C++] Re-proposal of 'divmod' in Compute Functions
https://lists.apache.org/thread/h3t6nz1ys2k2hnbrjvwyoxkf70cps8sh
github-actions commentedon Jun 26, 2026
This issue has been marked as stale because it has had no activity in the past 365 days. Please remove the stale label or comment below, or this issue will be closed in 14 days. If this improvement is still desired but has no current owner, please add the 'Status: needs champion' label.
tadeja commentedon Sep 23, 2026
✏️ Note, there's further-reviews-welcome related PR #48914 (issue #46901) which would add single-result
remainder(truncated) andmodulo(floored) kernels.This issue should remain open for quotient and combined-kernel work. Might be
trunc_divmod ≡ [trunc_quotient, remainder]floor_divmod ≡ [floor_quotient, modulo]per
GH-46901: [C++][Compute] Add remainder and modulo kernels (#48914)