Is there a function in Base like isdivisible(m::Integer, n::Integer) that returns true if m is divisible by n? A straightforward implementation would be
isdivisible(m, n) = iszero(m % n)
Modulo works just fine for Ints, but it allocates for BigInts:
There is a function for that in GMP, which I am using (see below), but I am wondering if I am missing an implementation from Base.
function mpz_isdivisible(x::BigInt, y::Int)
r = ccall((:__gmpz_divisible_ui_p, Base.GMP.libgmp), Cint,
(Base.GMP.MPZ.mpz_t, Culong), x, y)
return r != 0
end
I don’t see why this should be in Base (things are moving out of Base, not into it), especially since the implementation is trivial, as you show: iszero(a % b). The performance issue can be helped by improving the performance of % for BigInt.