Extend `mod` first argument to Gaussian integers?

Would folks find it useful if mod(z,m) worked when z is a Gaussian integer? This is easy enough to implement:

import Base.mod

function mod(z::Complex{T}, m::Integer) where T<:Integer 
    a,b = reim(z)
    return mod(a,m) + mod(b,m)*im 
end 

I’m wondering if this should be included in Base?

5 Likes

In the package Grassmann I implemented such a method which applies mod to each coefficient in the TensorAlgebra, so I don’t see any issue with doing the same for Complex also. It wouldn’t cause any issues as far as I am aware. Try making a PR?

Have a look at https://github.com/JuliaLang/julia/pull/35374. If you are interested in this, fell free to bump that PR.

1 Like

Thanks folks, but I’m sufficiently inept at git that I wouldn’t know how to do the things you suggest. I’m just going to add Complex support to my Mods package.

That PR only has mod(::Complex, ::Complex), unless I’m missing something?

I filed an issue (https://github.com/JuliaLang/julia/issues/37376) — should be an easy first PR for someone wants to get their feet wet with contributing to Julia.

2 Likes