diff --git a/base/irrationals.jl b/base/irrationals.jl index 4b42aa9c05a26..9a5151ca16c95 100644 --- a/base/irrationals.jl +++ b/base/irrationals.jl @@ -136,6 +136,12 @@ hash(x::Irrational, h::UInt) = 3*objectid(x) - h widen(::Type{T}) where {T<:Irrational} = T +zero(::AbstractIrrational) = false +zero(::Type{<:AbstractIrrational}) = false + +one(::AbstractIrrational) = true +one(::Type{<:AbstractIrrational}) = true + -(x::AbstractIrrational) = -Float64(x) for op in Symbol[:+, :-, :*, :/, :^] @eval $op(x::AbstractIrrational, y::AbstractIrrational) = $op(Float64(x),Float64(y)) diff --git a/test/numbers.jl b/test/numbers.jl index 31761880f84c0..608c1d77317e4 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -1035,6 +1035,13 @@ end @test !(1 > NaN) end +@testset "Irrational zero and one" begin + @test one(pi) === true + @test zero(pi) === false + @test one(typeof(pi)) === true + @test zero(typeof(pi)) === false +end + @testset "Irrationals compared with Irrationals" begin for i in (π, ℯ, γ, catalan) for j in (π, ℯ, γ, catalan)