Skip to content

Commit 104a836

Browse files
committed
Fix some type stability issues
1 parent cd85294 commit 104a836

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/intervals/arithmetic.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ function inv(a::Interval{T}) where T<:Real
162162
isempty(a) && return emptyinterval(a)
163163

164164
if zero(T) a
165-
a.lo < zero(T) == a.hi && return @round(-Inf, inv(a.lo))
166-
a.lo == zero(T) < a.hi && return @round(inv(a.hi), Inf)
165+
a.lo < zero(T) == a.hi && return @round(T(-Inf), inv(a.lo))
166+
a.lo == zero(T) < a.hi && return @round(inv(a.hi), T(Inf))
167167
a.lo < zero(T) < a.hi && return entireinterval(T)
168168
a == zero(a) && return emptyinterval(T)
169169
end
@@ -195,14 +195,14 @@ function /(a::Interval{T}, b::Interval{T}) where T<:Real
195195

196196
if iszero(b.lo)
197197

198-
a.lo >= zero(T) && return @round(a.lo/b.hi, Inf)
199-
a.hi <= zero(T) && return @round(-Inf, a.hi/b.hi)
198+
a.lo >= zero(T) && return @round(a.lo/b.hi, T(Inf))
199+
a.hi <= zero(T) && return @round(T(-Inf), a.hi/b.hi)
200200
return entireinterval(S)
201201

202202
elseif iszero(b.hi)
203203

204-
a.lo >= zero(T) && return @round(-Inf, a.lo/b.lo)
205-
a.hi <= zero(T) && return @round(a.hi/b.lo, Inf)
204+
a.lo >= zero(T) && return @round(T(-Inf), a.lo/b.lo)
205+
a.hi <= zero(T) && return @round(a.hi/b.lo, T(Inf))
206206
return entireinterval(S)
207207

208208
else
@@ -218,10 +218,10 @@ function extended_div(a::Interval{T}, b::Interval{T}) where T<:Real
218218
S = typeof(a.lo / b.lo)
219219
if 0 < b.hi && 0 > b.lo && 0 a
220220
if a.hi < 0
221-
return (Interval(-Inf, a.hi / b.hi), Interval(a.hi / b.lo, Inf))
221+
return (Interval(T(-Inf), a.hi / b.hi), Interval(a.hi / b.lo, T(Inf)))
222222

223223
elseif a.lo > 0
224-
return (Interval(-Inf, a.lo / b.lo), Interval(a.lo / b.hi, Inf))
224+
return (Interval(T(-Inf), a.lo / b.lo), Interval(a.lo / b.hi, T(Inf)))
225225

226226
end
227227
elseif 0 a && 0 b
@@ -432,13 +432,13 @@ function mid(a::Interval{T}) where T
432432
a.lo == -&& return nextfloat(a.lo)
433433
a.hi == +&& return prevfloat(a.hi)
434434

435-
midpoint = 0.5 * (a.lo + a.hi)
435+
midpoint = (a.lo + a.hi) / 2
436436
isfinite(midpoint) && return midpoint
437437
#= Fallback in case of overflow: a.hi + a.lo == +∞ or a.hi + a.lo == -∞.
438438
This case can not be the default one as it does not pass several
439439
IEEE1788-2015 tests for small floats.
440440
=#
441-
return 0.5 * a.lo + 0.5 * a.hi
441+
return a.lo / 2 + a.hi / 2
442442
end
443443

444444
mid(a::Interval{Rational{T}}) where T = (1//2) * (a.lo + a.hi)

0 commit comments

Comments
 (0)