Skip to content

Commit

Permalink
Add standard midpoint method if no alpha given
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed May 1, 2017
1 parent 2a615f7 commit 5d65442
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/intervals/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ doc"""
Find the midpoint (or, in general, an intermediate point) at a distance α along the interval `a`. The default is the true midpoint at α=0.5.
"""
function mid{T}(a::Interval{T}, α=0.5)
function mid{T}(a::Interval{T}, α)

isempty(a) && return convert(T, NaN)
isentire(a) && return zero(a.lo)
Expand All @@ -326,8 +326,24 @@ function mid{T}(a::Interval{T}, α=0.5)
return α*(a.hi - a.lo) + a.lo # rounds to nearest
end

function mid{T}(a::Interval{T})

isempty(a) && return convert(T, NaN)
isentire(a) && return zero(a.lo)

a.lo == -&& return nextfloat(a.lo)
a.hi == +&& return prevfloat(a.hi)

# @assert 0 ≤ α ≤ 1

return simple_mid(a)
end

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

function simple_mid(a::Interval)
return 0.5*(a.lo + a.hi)
end

doc"""
diam(a::Interval)
Expand Down

0 comments on commit 5d65442

Please sign in to comment.