Skip to content

Commit

Permalink
Fix (-3.. -2)^2
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed Dec 11, 2018
1 parent 3243c63 commit cf5eae9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/intervals/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,22 @@ function ^(x::Interval, n::Integer) # fast integer power
return inv(x^(-n))
end

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

return Interval(zero(eltype(x)),
return Interval(zero(eltype(x)),
power_by_squaring(mag(x), n, RoundUp))

#elseif x.lo > 0
elseif x.lo > 0
return Interval(power_by_squaring(x.lo, n, RoundUp),
power_by_squaring(x.hi, n, RoundUp))

else
else # x.lo < x.hi < 0
return Interval(power_by_squaring(-x.hi, n, RoundUp),
power_by_squaring(-x.lo, n, RoundUp))
end

else # odd n

a = power_by_squaring(x.lo, n, RoundDown)
b = power_by_squaring(x.hi, n, RoundUp)
Expand Down

0 comments on commit cf5eae9

Please sign in to comment.