Skip to content

Commit

Permalink
zero and one for irrational numbers (#34773)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed82008 authored Feb 20, 2020
1 parent fb301f4 commit 6476458
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 7 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6476458

Please sign in to comment.