Skip to content

Commit 0acb83b

Browse files
authored
add mid radius inf sup diam for reals (#511)
1 parent 1e1dad2 commit 0acb83b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
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.20.4"
4+
version = "0.20.5"
55

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

src/intervals/arithmetic.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ end
305305
inf(a::Interval) = ifelse(iszero(a.lo) && !signbit(a.lo), copysign(a.lo, -1), a.lo)
306306
sup(a::Interval) = a.hi
307307

308+
inf(a::Real) = a
309+
sup(a::Real) = a
308310

309311
## Functions needed for generic linear algebra routines to work
310312
real(a::Interval) = a
@@ -512,6 +514,10 @@ function radius(a::Interval{Rational{T}}) where T
512514
return max(m - a.lo, a.hi - m)
513515
end
514516

517+
mid(a::Real) = a
518+
diam(a::Real) = zero(a)
519+
radius(a::Real) = zero(a)
520+
515521
# cancelplus and cancelminus
516522
"""
517523
cancelminus(a, b)

test/interval_tests/consistency.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ setprecision(Interval, Float64)
186186
@test inf(entireinterval(a)) == -Inf
187187
@test sup(entireinterval(a)) == Inf
188188
@test isnan(sup(nai(BigFloat)))
189+
190+
@test inf(2.5) == 2.5
191+
@test sup(2.5) == 2.5
189192
end
190193

191194
@testset "mid" begin
@@ -220,6 +223,8 @@ setprecision(Interval, Float64)
220223
@test diam( @interval(0.1) ) == eps(0.1)
221224
@test isnan(diam(emptyinterval()))
222225
@test diam(a) == 1.0000000000000002
226+
227+
@test diam(0.1) == 0
223228
end
224229

225230
@testset "mig and mag" begin
@@ -286,6 +291,9 @@ setprecision(Interval, Float64)
286291
else
287292
@test_throws InexactError nai(Interval(1//2))
288293
end
294+
295+
@test mid(2.125) == 2.125
296+
@test radius(2.125) == 0
289297
end
290298

291299
@testset "abs, min, max, sign" begin

0 commit comments

Comments
 (0)