Skip to content

Base: new function isdivisible #56212

@barucden

Description

@barucden

Base does not provide a function for checking divisibility:

"""
    isdivisible(m, n)

Return true if `m` is divisible by `n`.
"""
isdivisible(m::Integer, n::Integer)

It can be implemented as iszero(rem(m, n)) but that's not the optimal implementation for all types from Base (it allocates for a BigInt).

AbstractAlgebra.jl from Nemo implements this exact function: https://github.com/Nemocas/AbstractAlgebra.jl/blob/396fdddbc1d1620a7b2866e7340e39b14228176e/src/julia/Integer.jl#L121-L151
I would like to have it in Base.

(Discussed on Discourse: https://discourse.julialang.org/t/checking-divisibility-efficiently/121418)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requestsmathsMathematical functions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions