From e95b5d21425d6c757088d284f5a62adda4c7baa4 Mon Sep 17 00:00:00 2001 From: "David P. Sanders" Date: Fri, 9 Aug 2019 12:55:04 -0400 Subject: [PATCH] Fix power_rev for exponents that are integer-valued but not integer-typed (#38) * Treat exponent 2.0 as if it were 2 by calling the integer version of power_rev * Fix return type and add test * Bump version --- Project.toml | 2 +- src/arithmetic.jl | 5 +++++ test/runtests.jl | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3ba2059..2b143d9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "IntervalContractors" uuid = "15111844-de3b-5229-b4ba-526f2f385dc9" -version = "0.4.0" +version = "0.4.1" [deps] IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" diff --git a/src/arithmetic.jl b/src/arithmetic.jl index bd7c00d..ee645a6 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -120,6 +120,11 @@ end function power_rev(a::Interval, b::Interval, c::Interval) # a = b^c + if isinteger(c) + temp = power_rev(a, b, Int(inf(c))) # use version with integer + return (temp[1], temp[2], interval(temp[3])) + end + b_new = b ∩ ( a^(inv(c) )) c_new = c ∩ (log(a) / log(b)) diff --git a/test/runtests.jl b/test/runtests.jl index fa8b510..be1dfad 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -20,4 +20,8 @@ using Test @test mul_rev(z, x, y) == (2..10, 2..5, 0.4..1.0) end + + @testset "Exponents with integer values but not types" begin + @test power_rev(-Inf..Inf, -4..4, 2.0) == (-∞..∞, -4..4, 2.0) + end end