diff --git a/base/irrationals.jl b/base/irrationals.jl index 115e37d856acb..17486e0f4ceeb 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -56,6 +56,15 @@ float(::Type{<:AbstractIrrational}) = Float64 ==(::Irrational{s}, ::Irrational{s}) where {s} = true ==(::AbstractIrrational, ::AbstractIrrational) = false +<(::Irrational{s}, ::Irrational{s}) where {s} = false +function <(x::AbstractIrrational, y::AbstractIrrational) + Float64(x) != Float64(y) || throw(MethodError(<, (x, y))) + return Float64(x) < Float64(y) +end + +<=(::Irrational{s}, ::Irrational{s}) where {s} = true +<=(x::AbstractIrrational, y::AbstractIrrational) = x==y || x NaN) end +@testset "Irrationals compared with Irrationals" begin + for i in (π, ℯ, γ, catalan) + for j in (π, ℯ, γ, catalan) + @test isequal(i==j, Float64(i)==Float64(j)) + @test isequal(i!=j, Float64(i)!=Float64(j)) + @test isequal(i<=j, Float64(i)<=Float64(j)) + @test isequal(i>=j, Float64(i)>=Float64(j)) + @test isequal(ij, Float64(i)>Float64(j)) + end + end +end + @testset "Irrationals compared with Rationals and Floats" begin @test Float64(pi,RoundDown) < pi @test Float64(pi,RoundUp) > pi