Skip to content

Commit 358848b

Browse files
committed
Use typemax/typemin
1 parent e381c3f commit 358848b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/intervals/arithmetic/basic.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ function /(a::F, b::F) where {T<:NumTypes,F<:Interval{T}}
164164
isthinzero(a) && return a
165165

166166
if iszero(inf(b))
167-
inf(a) >= zero(T) && return @round(F, inf(a)/sup(b), T(Inf))
168-
sup(a) <= zero(T) && return @round(F, T(-Inf), sup(a)/sup(b))
167+
inf(a) >= zero(T) && return @round(F, inf(a)/sup(b), typemax(T))
168+
sup(a) <= zero(T) && return @round(F, typemin(T), sup(a)/sup(b))
169169
return entireinterval(F)
170170

171171
elseif iszero(sup(b))
172-
inf(a) >= zero(T) && return @round(F, T(-Inf), inf(a)/inf(b))
173-
sup(a) <= zero(T) && return @round(F, sup(a)/inf(b), T(Inf))
172+
inf(a) >= zero(T) && return @round(F, typemin(T), inf(a)/inf(b))
173+
sup(a) <= zero(T) && return @round(F, sup(a)/inf(b), typemax(T))
174174
return entireinterval(F)
175175

176176
else
@@ -192,8 +192,8 @@ function inv(a::F) where {T<:NumTypes,F<:Interval{T}}
192192
isempty(a) && return emptyinterval(F)
193193

194194
if zero(T) a
195-
inf(a) < zero(T) == sup(a) && return @round(F, T(-Inf), inv(inf(a)))
196-
inf(a) == zero(T) < sup(a) && return @round(F, inv(sup(a)), T(Inf))
195+
inf(a) < zero(T) == sup(a) && return @round(F, typemin(T), inv(inf(a)))
196+
inf(a) == zero(T) < sup(a) && return @round(F, inv(sup(a)), typemax(T))
197197
inf(a) < zero(T) < sup(a) && return entireinterval(F)
198198
isthinzero(a) && return div_by_thin_zero(one(F))
199199
end

src/intervals/rounding_macros.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ function round_expr(ex::Expr, rounding_mode::RoundingMode)
1313
if op (:min, :max)
1414
mapped_args = round_expr.(ex.args[2:end], rounding_mode)
1515
return :($op($(mapped_args...)))
16+
elseif op (:typemin, :typemax)
17+
return :( $(esc(ex)) )
1618
end
1719

1820
if length(ex.args) == 3 # binary operator

src/parsing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ function _parse(::Type{Interval{T}}, s::AbstractString) where {T<:NumTypes}
175175
m, _ = split(s, "??")
176176
if 'u' in s # interval in the form [m, Inf]
177177
lo = parse(T, m, RoundDown)
178-
hi = T(Inf)
178+
hi = typemax(T)
179179
elseif 'd' in s # interval in the form [-Inf, m]
180-
lo = T(-Inf)
180+
lo = typemin(T)
181181
hi = parse(T, m, RoundUp)
182182
else
183183
return entireinterval(T), true

0 commit comments

Comments
 (0)