Mod not defined for two identical irrationals

julia> mod(π,ℯ)

julia> mod(√2,π)

julia> mod(π,π)
ERROR: mod not defined for Irrational{:π}
 [1] error(::String, ::String, ::Type) at ./error.jl:42
 [2] no_op_err at ./promotion.jl:420 [inlined]
 [3] mod(::Irrational{:π}, ::Irrational{:π}) at ./promotion.jl:440
 [4] top-level scope

julia> versioninfo()
Julia Version 0.7.0-DEV.3686

Two identical irrational numbers don’t parse well by mod(). Is this a bug or by design?

Just to give a reason for why this happens (without commenting on if this is a bug or by design).

julia> typeof(promote(π, ℯ))

julia> typeof(promote(π, π))

So in the first case we will call the mod function with the irrationals converted to floats, but not in the second.

Perhaps something like

Base.mod(::Irrational{T}, ::Irrational{T}) where T = 0

& related could be used to cover this corner case.

1 Like

Thanks for the explanation. I don’t know if a corner case must be introduced, but of course I was expecting mod(π,π)==0.

I must be missing something, but I thought mod(x,x) should be 0.

Of course! Fixed :slight_smile:

This would make a nice small feature addition pull request.

1 Like

Yes, please open an issue!