Skip to content

Commit d97d79b

Browse files
committed
Make mid type stable
1 parent ef08499 commit d97d79b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/intervals/arithmetic.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ The default is the true midpoint at `α = 0.5`.
394394
395395
Assumes 0 ≤ α ≤ 1.
396396
397-
Warning: if the parameter `α = 0.5` is explicitely set, the behavior differs
397+
Warning: if the parameter `α = 0.5` is explicitly set, the behavior differs
398398
from the default case if the provided `Interval` is not finite, since when
399399
`α` is provided `mid` simply replaces `+∞` (respectively `-∞`) by `prevfloat(+∞)`
400400
(respecively `nextfloat(-∞)`) for the computation of the intermediate point.
@@ -406,13 +406,15 @@ function mid(a::Interval{T}, α) where T
406406
lo = (a.lo == -? nextfloat(-∞) : a.lo)
407407
hi = (a.hi == +? prevfloat(+∞) : a.hi)
408408

409-
midpoint = α * (hi - lo) + lo
409+
β = convert(T, α)
410+
411+
midpoint = β * (hi - lo) + lo
410412
isfinite(midpoint) && return midpoint
411413
#= Fallback in case of overflow: hi - lo == +∞.
412414
This case can not be the default one as it does not pass several
413415
IEEE1788-2015 tests for small floats.
414416
=#
415-
return (1-α) * lo + α * hi
417+
return (1 - β) * lo + β * hi
416418
end
417419

418420
"""

0 commit comments

Comments
 (0)