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

question

#1

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

#2

It would seem reasonable to define e.g.

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

#3

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?


#4

Shouldn’t it be:

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

etc?


#5

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


#7

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


#8

Thnx for update