Skip to content

Commit 6476458

Browse files
authored
zero and one for irrational numbers (#34773)
1 parent fb301f4 commit 6476458

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

base/irrationals.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ hash(x::Irrational, h::UInt) = 3*objectid(x) - h
136136

137137
widen(::Type{T}) where {T<:Irrational} = T
138138

139+
zero(::AbstractIrrational) = false
140+
zero(::Type{<:AbstractIrrational}) = false
141+
142+
one(::AbstractIrrational) = true
143+
one(::Type{<:AbstractIrrational}) = true
144+
139145
-(x::AbstractIrrational) = -Float64(x)
140146
for op in Symbol[:+, :-, :*, :/, :^]
141147
@eval $op(x::AbstractIrrational, y::AbstractIrrational) = $op(Float64(x),Float64(y))

test/numbers.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,13 @@ end
10351035
@test !(1 > NaN)
10361036
end
10371037

1038+
@testset "Irrational zero and one" begin
1039+
@test one(pi) === true
1040+
@test zero(pi) === false
1041+
@test one(typeof(pi)) === true
1042+
@test zero(typeof(pi)) === false
1043+
end
1044+
10381045
@testset "Irrationals compared with Irrationals" begin
10391046
for i in (π, ℯ, γ, catalan)
10401047
for j in (π, ℯ, γ, catalan)

0 commit comments

Comments
 (0)