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

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

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

It would seem reasonable to define e.g.

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

Ooooh, I know this one! :smiley: I had a similar problem with isfinite when applied to Irrationals (#12416). Currently == is defined for Irrationals like this. I can send a PR for the comparison operators. What others, besides these should be defined this way?

Shouldn’t it be:

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

etc?

2 Likes

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

Update: this has now been fixed in PR #27797 by @Per :slight_smile:

2 Likes

Thnx for update