Skip to content

Commit 0757194

Browse files
authored
Use AbstractIrrational instead of Irrational (#556)
* Use `AbstractIrrational` instead of `Irrational` * More changes
1 parent 2d021b4 commit 0757194

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

src/IntervalArithmetic.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ const Region{T} = Union{Interval{T}, IntervalBox{T}}
125125

126126
# These definitions has been put there because generated functions must be
127127
# defined after all methods they use.
128-
@generated function Interval{T}(x::Irrational) where T
128+
@generated function Interval{T}(x::AbstractIrrational) where T
129129
res = atomic(Interval{T}, x()) # Precompute the interval
130130
return :(return $res) # Set body of the function to return the precomputed result
131131
end
132132

133-
Interval{BigFloat}(x::Irrational) = atomic(Interval{BigFloat}, x)
134-
Interval(x::Irrational) = Interval{Float64}(x)
133+
Interval{BigFloat}(x::AbstractIrrational) = atomic(Interval{BigFloat}, x)
134+
Interval(x::AbstractIrrational) = Interval{Float64}(x)
135135

136136
end # module IntervalArithmetic

src/intervals/conversion.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ atomic(::Type{Interval{T}}, x::AbstractString) where T<:AbstractFloat =
8383
parse(T, string(x), RoundUp) )
8484
end
8585

86-
function atomic(::Type{Interval{T}}, x::Union{Irrational,Rational}) where {T<:AbstractFloat}
86+
function atomic(::Type{Interval{T}}, x::Union{AbstractIrrational,Rational}) where {T<:AbstractFloat}
8787
isinf(x) && return wideinterval(T(x))
8888

8989
Interval{T}( T(x, RoundDown), T(x, RoundUp) )
@@ -116,7 +116,7 @@ function atomic(::Type{Interval{T}}, x::S) where {T<:AbstractFloat, S<:AbstractF
116116
return atomic(Interval{T}, xrat)
117117
end
118118

119-
atomic(::Type{Interval{Irrational{T}}}, x::Irrational{S}) where {T, S} =
119+
atomic(::Type{Interval{T}}, x::S) where {T<:AbstractIrrational, S<:AbstractIrrational} =
120120
float(atomic(Interval{Float64}, x))
121121

122122
function atomic(::Type{Interval{T}}, x::Interval) where T<:AbstractFloat
@@ -129,12 +129,12 @@ atomic(::Type{Interval{T}}, x::Complex{Bool}) where T<:AbstractFloat =
129129

130130

131131
# Rational intervals
132-
function atomic(::Type{Interval{Rational{Int}}}, x::Irrational)
132+
function atomic(::Type{Interval{Rational{Int}}}, x::AbstractIrrational)
133133
a = float(atomic(Interval{BigFloat}, x))
134134
atomic(Interval{Rational{Int}}, a)
135135
end
136136

137-
function atomic(::Type{Interval{Rational{BigInt}}}, x::Irrational)
137+
function atomic(::Type{Interval{Rational{BigInt}}}, x::AbstractIrrational)
138138
a = atomic(Interval{BigFloat}, x)
139139
atomic(Interval{Rational{BigInt}}, a)
140140
end

src/intervals/intervals.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ Interval(a::T, b::S) where {T<:Real, S<:Real} = Interval(promote(a,b)...)
5353
# BigFloat or Rational{Integer} intervals.
5454
Interval(a::T, b::T) where T<:Integer = Interval(float(a), float(b))
5555

56-
# Constructors for Irrational
57-
# Single argument Irrational constructor are in IntervalArithmetic.jl
56+
# Constructors for AbstractIrrational
57+
# Single argument AbstractIrrational constructor are in IntervalArithmetic.jl
5858
# as generated functions need to be define last.
59-
Interval{T}(a::Irrational, b::Irrational) where {T<:Real} = Interval{T}(T(a, RoundDown), T(b, RoundUp))
60-
Interval{T}(a::Irrational, b::Real) where {T<:Real} = Interval{T}(T(a, RoundDown), b)
61-
Interval{T}(a::Real, b::Irrational) where {T<:Real} = Interval{T}(a, T(b, RoundUp))
59+
Interval{T}(a::AbstractIrrational, b::AbstractIrrational) where {T<:Real} = Interval{T}(T(a, RoundDown), T(b, RoundUp))
60+
Interval{T}(a::AbstractIrrational, b::Real) where {T<:Real} = Interval{T}(T(a, RoundDown), b)
61+
Interval{T}(a::Real, b::AbstractIrrational) where {T<:Real} = Interval{T}(a, T(b, RoundUp))
6262

63-
Interval(a::Irrational, b::Irrational) = Interval{Float64}(a, b)
64-
Interval(a::Irrational, b::Real) = Interval{Float64}(a, b)
65-
Interval(a::Real, b::Irrational) = Interval{Float64}(a, b)
63+
Interval(a::AbstractIrrational, b::AbstractIrrational) = Interval{Float64}(a, b)
64+
Interval(a::AbstractIrrational, b::Real) = Interval{Float64}(a, b)
65+
Interval(a::Real, b::AbstractIrrational) = Interval{Float64}(a, b)
6666

6767
Interval(x::Interval) = x
6868
Interval(x::Complex) = Interval(real(x)) + im*Interval(imag(x))
@@ -144,25 +144,25 @@ function ..(a::T, b::S) where {T, S}
144144
Interval(atomic(Interval{T}, a).lo, atomic(Interval{S}, b).hi)
145145
end
146146

147-
function ..(a::T, b::Irrational{S}) where {T, S}
147+
function ..(a::T, b::S) where {T, S<:AbstractIrrational}
148148
if !is_valid_interval(a, b)
149149
@warn "Invalid input, empty interval is returned"
150-
return emptyinterval(promote_type(T, Irrational{S}))
150+
return emptyinterval(promote_type(T, S))
151151
end
152-
R = promote_type(T, Irrational{S})
152+
R = promote_type(T, S)
153153
Interval(atomic(Interval{R}, a).lo, R(b, RoundUp))
154154
end
155155

156-
function ..(a::Irrational{T}, b::S) where {T, S}
156+
function ..(a::T, b::S) where {T<:AbstractIrrational, S}
157157
if !is_valid_interval(a, b)
158158
@warn "Invalid input, empty interval is returned"
159-
return emptyinterval(promote_type(Irrational{T}, S))
159+
return emptyinterval(promote_type(T, S))
160160
end
161-
R = promote_type(Irrational{T}, S)
161+
R = promote_type(T, S)
162162
return Interval(R(a, RoundDown), atomic(Interval{R}, b).hi)
163163
end
164164

165-
function ..(a::Irrational{T}, b::Irrational{S}) where {T, S}
165+
function ..(a::T, b::S) where {T<:AbstractIrrational, S<:AbstractIrrational}
166166
return interval(a, b)
167167
end
168168

0 commit comments

Comments
 (0)