Skip to content

Commit

Permalink
add mid radius inf sup diam for reals (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaferranti committed Mar 8, 2022
1 parent 1e1dad2 commit 0acb83b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IntervalArithmetic"
uuid = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
repo = "https://github.com/JuliaIntervals/IntervalArithmetic.jl.git"
version = "0.20.4"
version = "0.20.5"

[deps]
CRlibm = "96374032-68de-5a5b-8d9e-752f78720389"
Expand Down
6 changes: 6 additions & 0 deletions src/intervals/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ end
inf(a::Interval) = ifelse(iszero(a.lo) && !signbit(a.lo), copysign(a.lo, -1), a.lo)
sup(a::Interval) = a.hi

inf(a::Real) = a
sup(a::Real) = a

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

mid(a::Real) = a
diam(a::Real) = zero(a)
radius(a::Real) = zero(a)

# cancelplus and cancelminus
"""
cancelminus(a, b)
Expand Down
8 changes: 8 additions & 0 deletions test/interval_tests/consistency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ setprecision(Interval, Float64)
@test inf(entireinterval(a)) == -Inf
@test sup(entireinterval(a)) == Inf
@test isnan(sup(nai(BigFloat)))

@test inf(2.5) == 2.5
@test sup(2.5) == 2.5
end

@testset "mid" begin
Expand Down Expand Up @@ -220,6 +223,8 @@ setprecision(Interval, Float64)
@test diam( @interval(0.1) ) == eps(0.1)
@test isnan(diam(emptyinterval()))
@test diam(a) == 1.0000000000000002

@test diam(0.1) == 0
end

@testset "mig and mag" begin
Expand Down Expand Up @@ -286,6 +291,9 @@ setprecision(Interval, Float64)
else
@test_throws InexactError nai(Interval(1//2))
end

@test mid(2.125) == 2.125
@test radius(2.125) == 0
end

@testset "abs, min, max, sign" begin
Expand Down

2 comments on commit 0acb83b

@lbenet
Copy link
Member

@lbenet lbenet commented on 0acb83b Mar 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/56217

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.20.5 -m "<description of version>" 0acb83bb59c2db273efe47154360429b9ec3a3ca
git push origin v0.20.5

Please sign in to comment.