Skip to content

Commit 2d1d646

Browse files
authored
added issubset, mig, mag, mid for complex intervals (#483)
* added issubset, mig, mag, mid for complex intervals * bump patch version
1 parent bad28d8 commit 2d1d646

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "IntervalArithmetic"
22
uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
33
repo = "https://github.com/JuliaIntervals/IntervalArithmetic.jl.git"
4-
version = "0.19.0"
4+
version = "0.19.1"
55

66
[deps]
77
CRlibm = "96374032-68de-5a5b-8d9e-752f78720389"

src/intervals/complex.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2-
(x::Complex{Interval{T}}, y::Complex{Interval{T}}) where T = real(x) real(y) && imag(x) imag(y)
2+
for op in (:, :)
3+
@eval function $(op)(x::Complex{Interval{T}}, y::Complex{Interval{S}}) where {T, S}
4+
return $(op)(real(x), real(y)) && $(op)(imag(x), imag(y))
5+
end
6+
end
37

48
function ^(x::Complex{Interval{T}}, n::Integer) where {T}
59
if n < 0
@@ -116,4 +120,9 @@ end
116120
# # \left( |x|^p \right)^{1/p}.
117121
# function norm(z::Complex{T}, p=2) where T<:Interval
118122
# return (abs(z)^(p))^(1 / p)
119-
# end
123+
# end
124+
125+
# real functions
126+
mid(z::Complex{T}) where {T <: Interval} = mid(real(z)) + mid(imag(z)) * im
127+
mag(z::Complex{T}) where {T <: Interval} = sup(abs(z))
128+
mig(z::Complex{T}) where {T <: Interval} = inf(abs(z))

test/interval_tests/complex.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ using LinearAlgebra
88
b = @interval 4im + 3
99
c = (@interval -1 4) + (@interval 0 2)*im
1010

11+
@test a c
12+
@test a c
13+
@test (b c) == false
14+
@test (b c) == false
15+
1116
@test typeof(a) == Complex{IntervalArithmetic.Interval{Float64}}
1217
@test a == Interval(0) + Interval(1)*im
1318
@test a * a == Interval(-1)
@@ -58,3 +63,10 @@ end
5863
@test abs(y).lo == 0.0
5964
@test abs2(y).lo == 0.0
6065
end
66+
67+
@testset "real functions" begin
68+
x = (0..3) + (0..4)*im
69+
@test mag(x) == 5
70+
@test mig(x) == 0
71+
@test mid(x) == 1.5 + 2im
72+
end

0 commit comments

Comments
 (0)