Skip to content

[C++][Compute] Add quotient and modulo kernels #28497

Open

Description

@asfimport

Add a pair of binary kernels to compute the:

  • 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.

Reporter: Ian Cook / @ianmcook

Related issues:

PRs and other links:

Note: This issue was originally created as ARROW-12755. Please see the migration documentation for further details.

Activity

  1. asfimport commented on Jun 10, 2021

    @asfimport
    Author

    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.

  2. asfimport commented on Jul 29, 2021

    @asfimport
    Author

    yibocai#1:
    For the record, libdivide may 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.

  3. asfimport commented on Jul 29, 2021

    @asfimport
    Author

    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

  4. asfimport commented on Jul 29, 2021

    @asfimport
    Author

    Eduardo Ponce / @edponce:
    @cyb70289 thanks for the tips!

  5. asfimport commented on Jan 14, 2022

    @asfimport
    Author

    Krisztian Szucs / @kszucs:
    Since the PR is in draft, I'm postponing to 8.0

  6. asfimport commented on Oct 13, 2022

    @asfimport
    Author

    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.

  7. asfimport commented on Dec 15, 2022

    @asfimport
    Author

    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.

  8. asfimport commented on Dec 15, 2022

    @asfimport
    Author

    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.

  9. randolf-scholz commented on Apr 24, 2024

    @randolf-scholz

    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.

  10. deleted a comment from mike-jn on Dec 2, 2024
  11. kou commented on Jun 25, 2025

    @kou
    Member

    Related discussion:
    [DISCUSSION][C++] Re-proposal of 'divmod' in Compute Functions
    https://lists.apache.org/thread/h3t6nz1ys2k2hnbrjvwyoxkf70cps8sh

  12. github-actions commented on Jun 26, 2026

    @github-actions

    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.

  13. added
    Status: stale-warningIssues and PRs flagged as stale which are due to be closed if no indication otherwise
    on Jun 26, 2026
  14. added
    Status: needs championHigh impact issues which aren't being worked on but require a volunteer to move the task forward.
    on Aug 6, 2026
  15. reopened this on Aug 6, 2026
  16. removed
    Status: stale-warningIssues and PRs flagged as stale which are due to be closed if no indication otherwise
    on Sep 3, 2026
  17. tadeja commented on Sep 23, 2026

    @tadeja
    Member

    ✏️ 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

    Related discussion: [DISCUSSION][C++] Re-proposal of 'divmod' in Compute Functions https://lists.apache.org/thread/h3t6nz1ys2k2hnbrjvwyoxkf70cps8sh

  18. added a commit that references this issue on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions