Skip to content

Commit

Permalink
Fix mid using specialized version for alpha=0.5 (#24)
Browse files Browse the repository at this point in the history
* Fix IntervalBox subtyping; comment out intervalbox_macro

* Try using a VERSION test to define IntervalBox with correct subtyping on 0.5 and 0.6

* Specialised version of mid for alpha=0.5
  • Loading branch information
dpsanders authored May 19, 2017
1 parent 45e1162 commit 414456f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 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 @@ -325,6 +325,19 @@ function mid{T}(a::Interval{T}, α=0.5)
return (1-α) * a.lo + α * a.hi # rounds to nearest
end


function mid{T}(a::Interval{T}) # specialized version for α=0.5

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


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


Expand Down

0 comments on commit 414456f

Please sign in to comment.