diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index da977c46c..21c60a268 100644 --- a/src/IntervalArithmetic.jl +++ b/src/IntervalArithmetic.jl @@ -22,7 +22,7 @@ import Base: +, -, *, /, //, fma, <, >, ==, !=, ⊆, ^, <=, in, zero, one, eps, typemin, typemax, abs, abs2, real, min, max, - sqrt, exp, log, sin, cos, tan, cot, inv, cbrt, csc, hypot, sec, + sqrt, exp, log, sin, cos, tan, cot, inv, cbrt, csc, hypot, sec, exp2, exp10, log2, log10, asin, acos, atan, sinh, cosh, tanh, coth, csch, sech, asinh, acosh, atanh, sinpi, cospi, @@ -86,7 +86,7 @@ import Base: rounding, setrounding, setprecision ## Multidimensional export - IntervalBox + IntervalBox, symmetric_box ## Decorations export diff --git a/src/multidim/intervalbox.jl b/src/multidim/intervalbox.jl index 9c1d26b0e..897ce72fc 100644 --- a/src/multidim/intervalbox.jl +++ b/src/multidim/intervalbox.jl @@ -140,3 +140,19 @@ end hull(a::IntervalBox{N,T}, b::IntervalBox{N,T}) where {N,T} = IntervalBox(hull.(a[:], b[:])) hull(a::Vector{IntervalBox{N,T}}) where {N,T} = hull(a...) + +""" + zero(IntervalBox{N, T}) + +Return the zero interval box of dimension `N` in the numeric type `T`. +""" +zero(::Type{IntervalBox{N, T}}) where {N, T} = IntervalBox(zero(Interval{T}), N) +zero(x::IntervalBox{N, T}) where {N, T} = zero(typeof(x)) + +""" + symmetric_box(N, T) + +Return the symmetric interval box of dimension `N` in the numeric type `T`, +each side is `Interval(-1, 1)`. +""" +symmetric_box(N, ::Type{T}) where T<:Real = IntervalBox(Interval{T}(-1, 1), N) diff --git a/test/interval_tests/construction.jl b/test/interval_tests/construction.jl index adbf2f73e..a16f49a66 100644 --- a/test/interval_tests/construction.jl +++ b/test/interval_tests/construction.jl @@ -370,3 +370,8 @@ import IntervalArithmetic: force_interval @test force_interval(Inf, -Inf) == Interval(-Inf, Inf) @test_throws ArgumentError force_interval(NaN, 3) end + +@testset "Zero interval" begin + @test zero(Interval{Float64}) === Interval{Float64}(0, 0) + @test zero(0 .. 1) === Interval{Float64}(0, 0) +end diff --git a/test/multidim_tests/multidim.jl b/test/multidim_tests/multidim.jl index ce7539b1a..295fe5bf5 100644 --- a/test/multidim_tests/multidim.jl +++ b/test/multidim_tests/multidim.jl @@ -314,4 +314,10 @@ end @test hull(vb4) == ib4 end +@testset "Special box constructors" begin + @test zero(IntervalBox{2, Float64}) === IntervalBox(0 .. 0, 2) + @test zero((0..1) × (0..1)) === IntervalBox(0 .. 0, 2) + @test symmetric_box(2, Float64) === IntervalBox(-1 .. 1, 2) +end + end