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 

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


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 (mod(::Complex{<:Integer}, ::Integer) and div etc. · Issue #37376 · JuliaLang/julia · GitHub) — should be an easy first PR for someone wants to get their feet wet with contributing to Julia.