# Mod not defined for two identical irrationals

**URL:** https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153
**Category:** General Usage
**Tags:** question
**Created:** [April 4, 2018, 11:25am UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153 "2018-04-04T11:25:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mvhulten](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mvhulten/32/2444_2.png) [@mvhulten](https://discourse.julialang.org/u/mvhulten)
#### Post date: [April 4, 2018, 11:25am UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/1 "2018-04-04T11:25:08Z")

</div>

```julia
julia> mod(π,ℯ)
0.423310825130748

julia> mod(√2,π)
1.4142135623730951

julia> mod(π,π)
ERROR: mod not defined for Irrational{:π}
Stacktrace:
 [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?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [April 4, 2018, 11:29am UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/2 "2018-04-04T11:29:30Z")

</div>

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

```julia
julia> typeof(promote(π, ℯ))
Tuple{Float64,Float64}

julia> typeof(promote(π, π))
Tuple{Irrational{:π},Irrational{:π}}

```

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

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 4, 2018, 11:37am UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/3 "2018-04-04T11:37:37Z")

</div>

Perhaps something like

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

```

& related could be used to cover this corner case.

---

<div class="post-metadata">

### Author: ![mvhulten](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mvhulten/32/2444_2.png) [@mvhulten](https://discourse.julialang.org/u/mvhulten)
#### Post date: [April 4, 2018, 11:46am UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/4 "2018-04-04T11:46:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 4, 2018, 11:49am UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/5 "2018-04-04T11:49:49Z")

</div>

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

---

<div class="post-metadata">

### Author: ![mvhulten](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mvhulten/32/2444_2.png) [@mvhulten](https://discourse.julialang.org/u/mvhulten)
#### Post date: [April 4, 2018, 11:50am UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/6 "2018-04-04T11:50:52Z")

</div>

Of course! Fixed 🙂

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [April 4, 2018, 3:18pm UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/7 "2018-04-04T15:18:14Z")

</div>

This would make a nice small feature addition pull request.

---

<div class="post-metadata">

### Author: ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)
#### Post date: [April 4, 2018, 4:17pm UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/8 "2018-04-04T16:17:22Z")

</div>

Yes, please open an issue!

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [April 4, 2018, 6:56pm UTC](https://discourse.julialang.org/t/mod-not-defined-for-two-identical-irrationals/10153/9 "2018-04-04T18:56:35Z")

</div>

opened: [https://github.com/JuliaLang/julia/issues/26701](https://github.com/JuliaLang/julia/issues/26701)
