# Comparison of Same Irrationals by \`\< , \> , \<=, \>=\` Throws Error

**URL:** <https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 7, 2017, 2:47pm UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342 "2017-01-07T14:47:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [January 7, 2017, 2:47pm UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342/1 "2017-01-07T14:47:48Z")

</div>

In julia 0.5, irrationals cannot be compared by itself other than equality. I think for completeness an irrational compared with itself with those methods should be defined. Is there any reason not to? Sample results in julia 0.5

```julia
xxxx@XXXX:~$ julia
               _
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: http://docs.julialang.org
   _ _ _| |_ __ _ | Type "?help" for help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.5.0 (2016-09-19 18:14 UTC)
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-pc-linux-gnu

julia> e<=e
ERROR: <= not defined for Irrational{:e}
 in <=(::Irrational{:e}, ::Irrational{:e}) at ./promotion.jl:271

julia> e<e
ERROR: < not defined for Irrational{:e}
 in <(::Irrational{:e}, ::Irrational{:e}) at ./promotion.jl:270

julia> pi<pi
ERROR: < not defined for Irrational{:π}
 in <(::Irrational{:π}, ::Irrational{:π}) at ./promotion.jl:270

julia> pi>e
true

julia> catalan > e
false

julia> catalan > catalan
ERROR: < not defined for Irrational{:catalan}
 in >(::Irrational{:catalan}, ::Irrational{:catalan}) at ./operators.jl:64

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 7, 2017, 4:37pm UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342/2 "2017-01-07T16:37:53Z")

</div>

It would seem reasonable to define e.g.

```julia
<(::Irrational{:π}, ::Irrational{:π}) = false
<=(::Irrational{:π}, ::Irrational{:π}) = true

```

---

<div class="post-metadata">

**Author:** ![waldyrious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waldyrious/32/80_2.png) [@waldyrious](https://discourse.julialang.org/u/waldyrious)\
**Post date:** [January 7, 2017, 7:34pm UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342/3 "2017-01-07T19:34:02Z")

</div>

Ooooh, I know this one! 😃 I had a similar problem with `isfinite` when applied to Irrationals ([#12416](https://github.com/JuliaLang/julia/pull/12416)). Currently `==` is defined for Irrationals [like this](https://github.com/JuliaLang/julia/blob/28a11ffd4d2e8451492013f18dad5e9a576233f6/base/irrationals.jl#L40). I can send a PR for the comparison operators. What [others](https://github.com/JuliaLang/julia/blob/master/base/operators.jl), besides these should be defined this way?

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [January 7, 2017, 9:51pm UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342/4 "2017-01-07T21:51:16Z")

</div>

> [@dpsanders](#):
>
> It would seem reasonable to define e.g.
> 
> \<(::Irrational{:π}, ::Irrational{:π}) = false  
> \<=(::Irrational{:π}, ::Irrational{:π}) = true

Shouldn’t it be:

```julia
<{S}(::Irrational{S}, ::Irrational{S}) = false
<={S}(::Irrational{S}, ::Irrational{S}) = true

```

etc?

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [January 7, 2017, 10:43pm UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342/5 "2017-01-07T22:43:13Z")

</div>

Yes, I thought it would have to be done by metaprogramming, but you’re completely correct.

---

<div class="post-metadata">

**Author:** ![waldyrious](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/waldyrious/32/80_2.png) [@waldyrious](https://discourse.julialang.org/u/waldyrious)\
**Post date:** [June 29, 2018, 11:35am UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342/7 "2018-06-29T11:35:49Z")

</div>

**Update** : this has now been fixed in [PR #27797](https://github.com/JuliaLang/julia/pull/27797) by @Per 🙂

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [June 29, 2018, 12:01pm UTC](https://discourse.julialang.org/t/comparison-of-same-irrationals-by-throws-error/1342/8 "2018-06-29T12:01:14Z")

</div>

Thnx for update
