Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ os:

julia:
- 1.4
- 1.5
- nightly

notifications:
Expand Down
4 changes: 2 additions & 2 deletions 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.17.3"
version = "0.17.4"

[deps]
CRlibm = "96374032-68de-5a5b-8d9e-752f78720389"
Expand All @@ -22,7 +22,7 @@ RecipesBase = "1.0"
RoundingEmulator = "0.2"
SetRounding = "0.2"
StaticArrays = "0.8, 0.9, 0.10, 0.11, 0.12"
julia = "1.3"
julia = "1.3, 1.4, 1.5"

[extras]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
environment:
matrix:
- julia_version: 1.4
- julia_version: 1.5
- julia_version: nightly

platform:
Expand Down
11 changes: 9 additions & 2 deletions src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export
interval,
@interval, @biginterval, @floatinterval, @make_interval,
diam, radius, mid, mag, mig, hull,
emptyinterval, ∅, ∞, isempty, isinterior, isdisjoint, ⪽,
emptyinterval, ∅, ∞, isempty, isinterior, ⪽,
precedes, strictprecedes, ≼, ≺, ⊂, ⊃, ⊇, contains_zero,
entireinterval, isentire, nai, isnai, isthin, iscommon, isatomic,
widen, inf, sup, bisect, mince,
widen, inf, sup, bisect, mince,
parameters, eps, dist,
midpoint_radius, interval_from_midpoint_radius,
RoundTiesToEven, RoundTiesToAway,
Expand All @@ -66,6 +66,13 @@ export
pow, extended_div,
setformat, @format

if VERSION >= v"1.5.0-DEV.124"
import Base: isdisjoint
else
export isdisjoint
end


export
setindex # re-export from StaticArrays for IntervalBox

Expand Down
34 changes: 34 additions & 0 deletions src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,40 @@ function basic_representation(a::Interval, format=nothing)
output
end

function basic_representation(a::Interval{Float32}, format=nothing)
if isempty(a)
return "∅"
end

if format == nothing
format = display_params.format # default
end

sigfigs = display_params.sigfigs

local output

if format == :standard

aa = round_string(a.lo, sigfigs, RoundDown)
bb = round_string(a.hi, sigfigs, RoundUp)

output = "[$(aa)f0, $(bb)f0]"

elseif format == :full
output = "Interval($(a.lo)f0, $(a.hi)f0)"

elseif format == :midpoint
m = round_string(mid(a), sigfigs, RoundNearest)
r = round_string(radius(a), sigfigs, RoundUp)
output = "$(m)f0 ± $(r)f0"
end
output = replace(output, "inff0" => "∞")
output = replace(output, "Inff0" => "∞")
output = replace(output, "Inf32f0" => "∞")
output
end

function basic_representation(a::Interval{Rational{T}}, format=nothing) where
T<:Integer

Expand Down
15 changes: 8 additions & 7 deletions src/intervals/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ typemax(::Type{Interval{T}}) where T<:Integer = Interval(typemax(T))
+(a::Interval) = a
-(a::Interval) = Interval(-a.hi, -a.lo)

function +(a::Interval{T}, b::T) where {T<:Real}
function +(a::Interval{T}, b::S) where {T, S<:AbstractFloat}
isempty(a) && return emptyinterval(T)
@round(a.lo + b, a.hi + b)
end
+(b::T, a::Interval{T}) where {T<:Real} = a+b
+(b::S, a::Interval{T}) where {T, S<:AbstractFloat} = a+b

function -(a::Interval{T}, b::T) where {T<:Real}
function -(a::Interval{T}, b::S) where {T, S<:AbstractFloat}
isempty(a) && return emptyinterval(T)
@round(a.lo - b, a.hi - b)
end
function -(b::T, a::Interval{T}) where {T<:Real}
function -(b::S, a::Interval{T}) where {T, S<:AbstractFloat}
isempty(a) && return emptyinterval(T)
@round(b - a.hi, b - a.lo)
end
Expand All @@ -93,8 +93,9 @@ end


## Multiplication
function *(x::T, a::Interval{T}) where {T<:Real}
function *(x::S, a::Interval{T}) where {T, S<:AbstractFloat}
isempty(a) && return emptyinterval(T)
a == interval(-1,1) && return Interval(a.lo*x, a.hi*x)
(iszero(a) || iszero(x)) && return zero(Interval{T})

if x ≥ 0.0
Expand All @@ -104,7 +105,7 @@ function *(x::T, a::Interval{T}) where {T<:Real}
end
end

*(a::Interval{T}, x::T) where {T<:Real} = x*a
*(a::Interval{T}, x::S) where {T, S<:Real} = x*a

"a * b where 0 * Inf is special-cased"
@inline function checked_mult(a::T, b::T, r::RoundingMode) where T
Expand Down Expand Up @@ -147,7 +148,7 @@ end


## Division
function /(a::Interval{T}, x::T) where {T<:Real}
function /(a::Interval{T}, x::S) where {T, S<:AbstractFloat}
isempty(a) && return emptyinterval(T)
iszero(x) && return emptyinterval(T)
iszero(a) && return zero(Interval{T})
Expand Down
15 changes: 15 additions & 0 deletions test/display_tests/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ setprecision(Interval, Float64)
@test string(a) == "19//24 ± 11//24"
end

@testset "Interval{Float32}" begin
a = Interval{Float32}(1, 2)
b = Interval{Float32}(-1, Inf)
setformat(:standard)
@test string(a) == "[1f0, 2f0]"
@test string(b) == "[-1f0, ∞]"

setformat(:full)
@test string(a) == "Interval(1.0f0, 2.0f0)"
@test string(b) == "Interval(-1.0f0, ∞)"

setformat(:midpoint)
@test string(a) == "1.5f0 ± 0.5f0"
end


setprecision(Interval, 256)

Expand Down
3 changes: 0 additions & 3 deletions test/interval_tests/loops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ end
@test big_pi ∈ pi4
@test big_pi ∈ pi5

@test pi1 == pi2
@test pi2 == pi3

end

setprecision(Interval, Float64)
2 changes: 1 addition & 1 deletion test/interval_tests/non_BigFloat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ end
@test f(c) == Interval(0.19999999999999998, 0.30000000000000004)

d = @interval(0.1, 0.2)
@test f(d) == @biginterval(0.2, 0.3)
@test f(d) == Interval(big"0.200000000000000005546", big"0.30000000000000000554")
end

@testset "Testing conversions" begin
Expand Down