Skip to content

Commit

Permalink
Add pow for interval^real and interval^interval
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed May 27, 2017
1 parent 64f72c7 commit b35e627
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/intervals/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,18 @@ function sqrt{T}(a::Interval{T})
@round(sqrt(a.lo), sqrt(a.hi)) # `sqrt` is correctly-rounded
end

doc"""
"""
pow(x::Interval, n::Integer)
A faster implementation of `x^n` using `power_by_squaring`.
`pow(x, n) will usually return an interval that is slightly larger than that calculated by `x^n`, but is guaranteed to be a correct
A faster implementation of ``x^n``, currently using `power_by_squaring`.
`pow(x, n)` will usually return an interval that is slightly larger than that calculated by `x^n`, but is guaranteed to be a correct
enclosure when using multiplication with correct rounding.
"""
function pow{T}(x::Interval{T}, n::Integer) # fast integer power
function pow(x::Interval, n::Integer) # fast integer power

isempty(x) && return x

if iseven(n) && zero(T) x
if iseven(n) && 0 x

return hull(zero(x),
hull(Base.power_by_squaring(Interval(mig(x)), n),
Expand All @@ -197,6 +197,14 @@ function pow{T}(x::Interval{T}, n::Integer) # fast integer power

end

function pow(x::Interval, y::Real) # fast real power, including for y an Interval

isempty(x) && return x

return exp(y * log(x))

end




Expand Down

0 comments on commit b35e627

Please sign in to comment.