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 28, 2017
1 parent beb6c19 commit c5a5e4f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/intervals/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,21 +326,24 @@ function mid{T}(a::Interval{T}, α)
return α*(a.hi - a.lo) + a.lo # rounds to nearest
end


function mid{T}(a::Interval{T}) # specialized version for α=0.5
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)

return 0.5 * (a.lo + a.hi) # rounds to nearest
end
# @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 c5a5e4f

Please sign in to comment.