From da493b596e93dc98a4abf18bdc9f29c76ebb0a68 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Tue, 25 Sep 2018 21:54:30 -0500 Subject: [PATCH] Fix (-3.. -2)^2 --- src/intervals/functions.jl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/intervals/functions.jl b/src/intervals/functions.jl index d09bc2e00..6d2b51de3 100644 --- a/src/intervals/functions.jl +++ b/src/intervals/functions.jl @@ -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)