Skip to content

Commit

Permalink
Modify interval power in minimal way to improve precision of a^b for …
Browse files Browse the repository at this point in the history
…rational b
  • Loading branch information
dpsanders committed Apr 13, 2016
1 parent 42bd337 commit 8d15dee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/intervals/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function ^(a::Interval{BigFloat}, x::AbstractFloat)
a = a domain
(isempty(x) || isempty(a)) && return emptyinterval(a)

xx = @interval(x)
xx = convert(Interval{BigFloat}, x)

lo = @round(T, a.lo^xx.lo, a.lo^xx.lo)
lo1 = @round(T, a.lo^xx.hi, a.lo^xx.hi)
Expand Down Expand Up @@ -129,10 +129,9 @@ function ^{S<:Integer}(a::Interval{BigFloat}, r::Rational{S})
a = a domain
(isempty(r) || isempty(a)) && return emptyinterval(a)

r = r.num / r.den
a = a^r
y = convert(Interval{BigFloat}, r)

convert(Interval{T}, a)
a^y
end

# Interval power of an interval:
Expand Down
2 changes: 1 addition & 1 deletion test/interval_tests/numeric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ facts("Power tests") do
@fact @interval(1,27)^@interval(1/3) --> roughly(Interval(1., 3.))
@fact @interval(1,27)^(1/3) --> roughly(Interval(1., 3.))
@fact Interval(1., 3.) @interval(1,27)^(1//3) --> true
@fact @interval(0.1,0.7)^(1//3) --> Interval(0.4641588833612778, 0.8879040017426008)
@fact @interval(0.1,0.7)^(1//3) --> Interval(0.46415888336127786, 0.8879040017426008)
@fact @interval(0.1,0.7)^(1/3) --> roughly(Interval(0.46415888336127786, 0.8879040017426008))

end
Expand Down

0 comments on commit 8d15dee

Please sign in to comment.