diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e6e164ba..160590f6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: version: - - '1.9' + - '1.10' - '1' - 'nightly' os: diff --git a/Project.toml b/Project.toml index e92c8737..43686918 100644 --- a/Project.toml +++ b/Project.toml @@ -7,6 +7,7 @@ version = "0.22.30" CRlibm = "96374032-68de-5a5b-8d9e-752f78720389" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" OpenBLASConsistentFPCSR_jll = "6cdc7f73-28fd-5e50-80fb-958a8875b1af" +Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" RoundingEmulator = "5eaf0fd0-dfba-4ccb-bf02-d820a40db705" [weakdeps] @@ -28,12 +29,13 @@ IntervalArithmeticSparseArraysExt = "SparseArrays" [compat] CRlibm = "1.0.2" DiffRules = "1" -ForwardDiff = "0.10, 1" +ForwardDiff = "1" IntervalSets = "0.7" -LinearAlgebra = "1.9" +LinearAlgebra = "1.10" MacroTools = "0.5" OpenBLASConsistentFPCSR_jll = "0.3.29" +Printf = "1.10" RecipesBase = "1" RoundingEmulator = "0.2" -SparseArrays = "1.9.0" -julia = "1.9" +SparseArrays = "1.10" +julia = "1.10" diff --git a/README.md b/README.md index c1430053..20b40e79 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The official documentation is available online: https://juliaintervals.github.io ## Installation -The IntervalArithmetic.jl package requires to [install Julia](https://julialang.org/downloads/) (v1.9 or above). +The IntervalArithmetic.jl package requires to [install Julia](https://julialang.org/downloads/) (v1.10 or above). Then, start Julia and execute the following command in the REPL: diff --git a/docs/src/index.md b/docs/src/index.md index 455bab47..16b4b0c4 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -7,7 +7,7 @@ IntervalArithmetic.jl is a Julia package for validated numerics in Julia. All ca ## Installation ```@repl -using Pkg # Julia v1.9 or above +using Pkg # Julia v1.10 or above redirect_stderr(devnull) do # hide Pkg.add("IntervalArithmetic") end # hide diff --git a/ext/IntervalArithmeticForwardDiffExt.jl b/ext/IntervalArithmeticForwardDiffExt.jl index de64f6d1..a789cc21 100644 --- a/ext/IntervalArithmeticForwardDiffExt.jl +++ b/ext/IntervalArithmeticForwardDiffExt.jl @@ -23,8 +23,10 @@ Base.promote_rule(::Type{ExactReal{S}}, ::Type{Dual{T, V, N}}) where {S<:Real, T Base.promote_rule(::Type{Dual{T, V, N}}, ::Type{ExactReal{S}}) where {S<:Real, T, V, N} = Dual{T,ExactReal{IntervalArithmetic.promote_numtype(V, S)},N} -Base.:(==)(x::Union{BareInterval,Interval}, y::Dual) = x == value(y) -Base.:(==)(x::Dual, y::Union{BareInterval,Interval}) = value(x) == y +Base.:(==)(x::Interval, y::Dual) = x == value(y) +Base.:(==)(x::Dual, y::Interval) = value(x) == y +Base.:<(x::Interval, y::Dual) = x < value(y) +Base.:<(x::Dual, y::Interval) = value(x) < y function Base.:(^)(x::Dual{Txy,<:Interval}, y::Dual{Txy,<:Interval}) where {Txy} vx, vy = value(x), value(y) @@ -91,10 +93,9 @@ function Base.:(^)(x::ExactReal, y::Dual{<:Ty}) where {Ty} end end - # Piecewise functions -function (constant::Constant)(::Dual{T, Interval{S}}) where {T, S} +function (constant::Constant)(::Dual{T,Interval{S}}) where {T, S} return Dual{T}(interval(S, constant.value), interval(S, 0.0)) end diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index 0c7ac177..35402f61 100644 --- a/src/IntervalArithmetic.jl +++ b/src/IntervalArithmetic.jl @@ -77,6 +77,8 @@ include("piecewise.jl") # +import Printf + include("display.jl") export setdisplay @@ -205,7 +207,7 @@ Configure the default behavior for: definition of matrix multiplication. Learn more: [`IntervalArithmetic.MatMulMode`](@ref). """ -function configure(; numtype::Type{<:NumTypes}=Float64, flavor::Symbol=:set_based, rounding::Symbol=:correct, power::Symbol=:fast, matmul::Symbol=:slow) +function configure(; numtype::Type{<:NumTypes}=Float64, flavor::Symbol=:set_based, rounding::Symbol=:correct, power::Symbol=:fast, matmul::Symbol=:fast) configure_numtype(numtype) configure_flavor(flavor) configure_rounding(rounding) diff --git a/src/display.jl b/src/display.jl index 5928eac4..03ca9cbc 100644 --- a/src/display.jl +++ b/src/display.jl @@ -49,7 +49,7 @@ Display options: - significant digits: 6 julia> x = interval(0.1, 0.3) -[0.0999999, 0.300001]_com +[0.1, 0.3]_com julia> setdisplay(:full) Display options: @@ -69,7 +69,7 @@ Display options: - significant digits: 3 julia> x -[0.0999, 0.301]_com +[0.1, 0.3]_com julia> setdisplay(; decorations = false) Display options: @@ -79,7 +79,7 @@ Display options: - significant digits: 3 julia> x -[0.0999, 0.301] +[0.1, 0.3] ``` """ function setdisplay(format::Symbol = display_options.format; @@ -312,41 +312,41 @@ end # code inspired by `_string(x::BigFloat, k::Integer)` in base/mpfr.jl function _round_string(x::T, sigdigits::Int, r::RoundingMode) where {T<:AbstractFloat} - str_x = string(x) - str_digits = split(contains(str_x, '.') ? split(str_x, '.'; limit = 2)[2] : str_x, 'e'; limit = 2)[1] - len = length(str_digits) - if isinteger(x) && sigdigits ≥ len # `x` is exactly representable - return replace(_round_string(big(x), length(str_x), RoundNearest), "e-0" => "e-") - elseif ispow2(abs(x)) && sigdigits ≥ len # `x` is exactly representable - return replace(_round_string(big(x), len + 1, RoundNearest), "e-0" => "e-") - else - return _round_string(big(x), sigdigits, r) - end -end + !isfinite(x) && return string(x) -_round_string(x::BigFloat, sigdigits::Int, ::RoundingMode{:Nearest}) = - Base.MPFR._string(x, sigdigits-1) # `sigdigits-1` digits after the decimal + ndigits = ceil(Int, precision(x) * log10(T(2))) + sci_str = Printf.@sprintf("%.*e", ndigits, x) -function _round_string(x::BigFloat, sigdigits::Int, r::RoundingMode) - if !isfinite(x) - return string(Float64(x)) - else - str_x = string(x) - str_digits = split(split(str_x, '.'; limit = 2)[2], 'e'; limit = 2)[1] - len = length(str_digits) - if isinteger(x) && sigdigits ≥ len # `x` is exactly representable - return _round_string(big(x), length(str_x), RoundNearest) - elseif ispow2(abs(x)) && sigdigits ≥ len # `x` is exactly representable - return _round_string(big(x), len + 1, RoundNearest) - else - # `sigdigits` digits after the decimal - str = Base.MPFR.string_mpfr(x, "%.$(sigdigits)Re") - rounded_str = _round_string(str, r) - return Base.MPFR._prettify_bigfloat(rounded_str) + if abs(x) < floatmax(T) + ndigits_ = ndigits - 1 + sci_str_ = Printf.@sprintf("%.*e", ndigits_, x) + + if parse(T, sci_str) == parse(T, sci_str_) + ndigits = ndigits_ + sci_str = sci_str_ end end + + mantissa = split(sci_str, 'e')[1] + + mantissa_digits = replace(mantissa, "." => "") + + significant_digits = length(rstrip(mantissa_digits, '0')) + + is_representable = significant_digits ≤ sigdigits + + # `min(sigdigits-1, ndigits)` ensure we do not exceed the precision of `x` + str = is_representable ? Printf.@sprintf("%.*e", min(sigdigits-1, ndigits), x) : _round_string(Printf.@sprintf("%.*e", sigdigits, x), r) + + return Base.MPFR._prettify_bigfloat(str) end +_round_string(x::AbstractFloat, sigdigits::Int, r::RoundingMode{:Nearest}) = + _round_string(big(x), sigdigits, r) + +_round_string(x::BigFloat, sigdigits::Int, ::RoundingMode{:Nearest}) = + Base.MPFR._string(x, sigdigits-1) # `sigdigits-1` digits after the decimal + _round_string(s::String, ::RoundingMode{:Up}) = startswith(s, '-') ? string('-', _round_string_down(s[2:end])) : _round_string_up(s) diff --git a/src/intervals/real_interface.jl b/src/intervals/real_interface.jl index 8690301c..6d527ea3 100644 --- a/src/intervals/real_interface.jl +++ b/src/intervals/real_interface.jl @@ -78,96 +78,77 @@ Base.hash(x::Interval, h::UInt) = hash(sup(x), hash(inf(x), hash(Interval, h))) # -for T ∈ (:BareInterval, :Interval) - @eval begin - function Base.:(==)(x::$T, y::$T) # also returned when calling `≤`, `≥`, `isequal` - isthin(x) && return sup(x) == y - isthin(y) && return x == sup(y) - return throw(ArgumentError("`==` is purposely not supported when the intervals are overlapping. See instead `isequal_interval`")) - end - - Base.:<(::$T, ::$T) = # also returned when calling `isless`, `>` - throw(ArgumentError("`<` is purposely not supported for intervals. See instead `isstrictless`, `strictprecedes`")) - - Base.isdisjoint(::$T, ::$T) = - throw(ArgumentError("`isdisjoint` is purposely not supported for intervals. See instead `isdisjoint_interval`")) - - Base.issubset(::$T, ::$T) = - throw(ArgumentError("`issubset` is purposely not supported for intervals. See instead `issubset_interval`")) - - Base.issetequal(::$T, ::$T) = - throw(ArgumentError("`issetequal` is purposely not supported for intervals. See instead `isequal_interval`")) - - Base.in(::$T, ::$T) = - throw(ArgumentError("`in` is purposely not supported for intervals. See instead `in_interval`")) - - Base.isempty(::$T) = - throw(ArgumentError("`isempty` is purposely not supported for intervals. See instead `isempty_interval`")) - - Base.isfinite(::$T) = # also returned when calling `isinf` - throw(ArgumentError("`isfinite` is purposely not supported for intervals. See instead `isbounded`")) - - Base.isnan(::$T) = - throw(ArgumentError("`isnan` is purposely not supported for intervals. See instead `isnai`")) - - Base.intersect(::$T) = - throw(ArgumentError("`intersect` is purposely not supported for intervals. See instead `intersect_interval`")) - - Base.union!(::BitSet, ::$T) = # needed to resolve ambiguity - throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) - Base.union!(::AbstractSet, ::$T) = # also returned when calling `intersect`, `symdiff` with intervals - throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) - Base.union!(::AbstractVector{S}, ::$T) where {S} = - throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) - Base.union!(::AbstractVector{S}, ::$T, ::Any, ::Any...) where {S} = - throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) - Base.union!(::AbstractVector{S}, ::$T, ::$T, ::Any...) where {S} = - throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) - Base.union!(::AbstractVector{S}, ::Any, ::$T, ::Any...) where {S} = - throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) - - Base.setdiff(::$T) = - throw(ArgumentError("`setdiff` is purposely not supported for intervals. See instead `interiordiff`")) - Base.setdiff!(::AbstractSet, ::$T) = - throw(ArgumentError("`setdiff!` is purposely not supported for intervals. See instead `interiordiff`")) - end +function Base.:(==)(x::Interval, y::Interval) # also returned when calling `≤`, `≥`, `isequal` + isthin(x) && return sup(x) == y + isthin(y) && return x == sup(y) + isdisjoint_interval(x, y) && return false + return throw(ArgumentError("`==` is purposely not supported when the intervals are overlapping. See instead `isequal_interval`")) end -Base.union!(::AbstractVector{S}, ::BareInterval, ::Interval, ::Any...) where {S} = + +function Base.:<(x::Interval, y::Interval) + isthin(x) && return sup(x) < y + isthin(y) && return x < sup(y) + strictprecedes(x, y) && return true + strictprecedes(y, x) && return false + return throw(ArgumentError("`<` is purposely not supported when the intervals are overlapping. See instead `strictprecedes`")) +end + +# Base.isdisjoint(::Interval, ::Interval) = +# throw(ArgumentError("`isdisjoint` is purposely not supported for intervals. See instead `isdisjoint_interval`")) + +# Base.issubset(::Interval, ::Interval) = +# throw(ArgumentError("`issubset` is purposely not supported for intervals. See instead `issubset_interval`")) + +# Base.issetequal(::Interval, ::Interval) = +# throw(ArgumentError("`issetequal` is purposely not supported for intervals. See instead `isequal_interval`")) + +# Base.in(::Interval, ::Interval) = +# throw(ArgumentError("`in` is purposely not supported for intervals. See instead `in_interval`")) + +Base.isempty(::Interval) = + throw(ArgumentError("`isempty` is purposely not supported for intervals. See instead `isempty_interval`")) + +Base.isfinite(::Interval) = # also returned when calling `isinf` + throw(ArgumentError("`isfinite` is purposely not supported for intervals. See instead `isbounded`")) + +Base.isnan(::Interval) = + throw(ArgumentError("`isnan` is purposely not supported for intervals. See instead `isnai`")) + +Base.intersect(::Interval) = + throw(ArgumentError("`intersect` is purposely not supported for intervals. See instead `intersect_interval`")) + +Base.union!(::BitSet, ::Interval) = # needed to resolve ambiguity + throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) +Base.union!(::AbstractSet, ::Interval) = # also returned when calling `intersect`, `symdiff` with intervals + throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) +Base.union!(::AbstractVector{S}, ::Interval) where {S} = throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) -Base.union!(::AbstractVector{S}, ::Interval, ::BareInterval, ::Any...) where {S} = +Base.union!(::AbstractVector{S}, ::Interval, ::Any, ::Any...) where {S} = + throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) +Base.union!(::AbstractVector{S}, ::Interval, ::Interval, ::Any...) where {S} = + throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) +Base.union!(::AbstractVector{S}, ::Any, ::Interval, ::Any...) where {S} = throw(ArgumentError("`union!` is purposely not supported for intervals. See instead `hull`")) +Base.setdiff(::Interval) = + throw(ArgumentError("`setdiff` is purposely not supported for intervals. See instead `interiordiff`")) +Base.setdiff!(::AbstractSet, ::Interval) = + throw(ArgumentError("`setdiff!` is purposely not supported for intervals. See instead `interiordiff`")) # pointwise equality -""" - ==(::BareInterval, ::Number) - ==(::Number, ::BareInterval) - ==(::Interval, ::Number) - ==(::Number, ::Interval) - -Test whether an interval is the singleton of a given number. In other words, the -result is true if and only if the interval contains only that number. - -!!! note - Comparison between intervals is purposely disallowed. Indeed, equality - between non-singleton intervals has distinct properties, notably ``x = y`` - does not imply ``x - y = 0``. See instead [`isequal_interval`](@ref). -""" -Base.:(==)(x::Union{BareInterval,Interval}, y::Number) = isthin(x, y) -Base.:(==)(x::Number, y::Union{BareInterval,Interval}) = y == x +Base.:(==)(x::Interval, y::Number) = !isthin(x) & in_interval(y, x) ? throw(ArgumentError("`==` is purposely not supported when the number is contained in the interval. See instead `isthin`")) : isthin(x, y) +Base.:(==)(x::Number, y::Interval) = y == x # needed to resolve ambiguity from irrationals.jl -Base.:(==)(x::Interval, y::AbstractIrrational) = isthin(x, y) +Base.:(==)(x::Interval, y::AbstractIrrational) = !isthin(x) & in_interval(y, x) ? throw(ArgumentError("`==` is purposely not supported when the number is contained in the interval. See instead `isthin`")) : isthin(x, y) Base.:(==)(x::AbstractIrrational, y::Interval) = y == x # needed to resolve ambiguity from complex.jl Base.:(==)(x::Interval, y::Complex) = isreal(y) & (real(y) == x) Base.:(==)(x::Complex, y::Interval) = y == x -# follows docstring of `Base.iszero` -Base.iszero(x::Union{BareInterval,Interval}) = isthinzero(x) -# follows docstring of `Base.isone` -Base.isone(x::Union{BareInterval,Interval}) = isthinone(x) +Base.:<(x::Interval, y::Real) = (!isthin(x) & in_interval(y, x)) | isempty_interval(x) ? throw(ArgumentError("`<` is purposely not supported when the number is contained in the interval, or if the interval is empty")) : sup(x) < y +Base.:<(x::Real, y::Interval) = (!isthin(y) & in_interval(x, y)) | isempty_interval(y) ? throw(ArgumentError("`<` is purposely not supported when the number is contained in the interval, or if the interval is empty")) : x < inf(y) + -# follows docstring of `Base.isinteger` -Base.isinteger(x::Union{BareInterval,Interval}) = isthininteger(x) +Base.isinteger(x::Interval) = !isthin(x) & !isdisjoint_interval(x, floor(x), ceil(x)) ? throw(ArgumentError("`isinteger` is purposely not supported for non-thin containing at least one integer. See instead `isthininteger`")) : isthininteger(x) diff --git a/test/aqua.jl b/test/aqua.jl index 88c10f32..3c585886 100644 --- a/test/aqua.jl +++ b/test/aqua.jl @@ -2,27 +2,25 @@ using Test using IntervalArithmetic using Aqua -if VERSION ≥ v"1.10" - @testset "Aqua tests (performance)" begin - # This tests that we don't accidentally run into - # https://github.com/JuliaLang/julia/issues/29393 - # Aqua.test_unbound_args(IntervalArithmetic) - ua = Aqua.detect_unbound_args_recursively(IntervalArithmetic) - @test length(ua) == 0 +@testset "Aqua tests (performance)" begin + # This tests that we don't accidentally run into + # https://github.com/JuliaLang/julia/issues/29393 + # Aqua.test_unbound_args(IntervalArithmetic) + ua = Aqua.detect_unbound_args_recursively(IntervalArithmetic) + @test length(ua) == 0 - # See: https://github.com/SciML/OrdinaryDiffEq.jl/issues/1750 - # Test that we're not introducing method ambiguities across deps - ambs = Aqua.detect_ambiguities(IntervalArithmetic; recursive = true) - pkg_match(pkgname, pkdir::Nothing) = false - pkg_match(pkgname, pkdir::AbstractString) = occursin(pkgname, pkdir) - filter!(x -> pkg_match("IntervalArithmetic", pkgdir(last(x).module)), ambs) - for method_ambiguity ∈ ambs - @show method_ambiguity - end - @test length(ambs) == 0 + # See: https://github.com/SciML/OrdinaryDiffEq.jl/issues/1750 + # Test that we're not introducing method ambiguities across deps + ambs = Aqua.detect_ambiguities(IntervalArithmetic; recursive = true) + pkg_match(pkgname, pkdir::Nothing) = false + pkg_match(pkgname, pkdir::AbstractString) = occursin(pkgname, pkdir) + filter!(x -> pkg_match("IntervalArithmetic", pkgdir(last(x).module)), ambs) + for method_ambiguity ∈ ambs + @show method_ambiguity end + @test length(ambs) == 0 +end - @testset "Aqua tests (additional)" begin - Aqua.test_all(IntervalArithmetic) - end +@testset "Aqua tests (additional)" begin + Aqua.test_all(IntervalArithmetic; ambiguities = VERSION ≥ v"1.11") end diff --git a/test/interval_tests/consistency.jl b/test/interval_tests/consistency.jl index 1f38c67a..532dcfe9 100644 --- a/test/interval_tests/consistency.jl +++ b/test/interval_tests/consistency.jl @@ -363,17 +363,20 @@ @testset "Disallowed `Real` functionalities" begin x, y = interval(1), interval(2) @test x != y - @test (interval(1, 2) != y) & (y != interval(1, 2)) + @test_throws ArgumentError interval(1, 2) != y + @test_throws ArgumentError y != interval(1, 2) @test_throws ArgumentError interval(1, 2) == interval(1, 2) - @test_throws ArgumentError x < y - @test_throws ArgumentError isdisjoint(x, y) - @test_throws ArgumentError issubset(x, y) - @test_throws ArgumentError issetequal(x, y) - @test_throws ArgumentError x ∈ y + @test x < y + @test isdisjoint(x, y) + @test !issubset(x, y) + @test_throws ArgumentError !issetequal(x, y) + @test x ∉ y @test_throws ArgumentError isempty(x) @test_throws ArgumentError isfinite(x) @test_throws ArgumentError isnan(x) @test isinteger(x) + @test !isinteger(interval(1.2, 1.9)) + @test_throws ArgumentError isinteger(interval(1.5, 2.5)) @test x == 1 @test isone(x) @test !iszero(x) diff --git a/test/interval_tests/display.jl b/test/interval_tests/display.jl index e1dd97bc..feb83471 100644 --- a/test/interval_tests/display.jl +++ b/test/interval_tests/display.jl @@ -12,18 +12,16 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), emptyinterval(BareInterval{Float64})) == "∅" - @test sprint(show, MIME("text/plain"), a) == "[-2.22508e-308, 1.30001]" - @test sprint(show, MIME("text/plain"), large_expo) == - "[0.0, 1.00001e+123456789]₂₅₆" + @test sprint(show, MIME("text/plain"), a) == "[-2.22508e-308, 1.3]" + @test sprint(show, MIME("text/plain"), large_expo) == "[0.0, 1.0e+123456789]₂₅₆" end @testset "20 significant digits" begin # `decorations` keyword has no impact for `BareInterval` setdisplay(; sigdigits = 20, decorations = true) - @test sprint(show, MIME("text/plain"), a) == "[-2.2250738585072014e-308, 1.3000000000000000445]" - @test sprint(show, MIME("text/plain"), large_expo) == - "[0.0, 1.0000000000000000001e+123456789]₂₅₆" + @test sprint(show, MIME("text/plain"), a) == "[-2.2250738585072014e-308, 1.3]" + @test sprint(show, MIME("text/plain"), large_expo) == "[0.0, 1.0e+123456789]₂₅₆" end end @@ -45,9 +43,8 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), emptyinterval(BareInterval{Float64})) == "∅" - @test sprint(show, MIME("text/plain"), a) == "0.65 ± 0.650001" - @test sprint(show, MIME("text/plain"), large_expo) == - "(5.0e+123456788 ± 5.00001e+123456788)₂₅₆" + @test sprint(show, MIME("text/plain"), a) == "0.65 ± 0.65" + @test sprint(show, MIME("text/plain"), large_expo) == "(5.0e+123456788 ± 5.00001e+123456788)₂₅₆" end end @@ -75,13 +72,12 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "[1.0, 2.0]_com" @test sprint(show, MIME("text/plain"), a_NG) == "[1.0, 2.0]_com_NG" - @test sprint(show, MIME("text/plain"), b) == "[-2.22508e-308, 1.30001]_com" - @test sprint(show, MIME("text/plain"), b32) == "[-1.1755f-38, 1.30001f0]_com" - @test sprint(show, MIME("text/plain"), b16) == "[Float16(-6.104e-5), Float16(1.29981)]_com" + @test sprint(show, MIME("text/plain"), b) == "[-2.22508e-308, 1.3]_com" + @test sprint(show, MIME("text/plain"), b32) == "[-1.1755f-38, 1.3f0]_com" + @test_broken sprint(show, MIME("text/plain"), b16) == "[Float16(-6.104e-5), Float16(1.3)]_com" @test sprint(show, MIME("text/plain"), br) == "[-11//10, 13//10]_com" @test sprint(show, MIME("text/plain"), c) == "[-1.0, ∞)_dac" - @test sprint(show, MIME("text/plain"), large_expo) == - "[0.0, 1.00001e+123456789]₂₅₆_com" + @test sprint(show, MIME("text/plain"), large_expo) == "[0.0, 1.0e+123456789]₂₅₆_com" end @testset "No decorations" begin @@ -92,13 +88,12 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "[1.0, 2.0]" @test sprint(show, MIME("text/plain"), a_NG) == "[1.0, 2.0]_NG" - @test sprint(show, MIME("text/plain"), b) == "[-2.22508e-308, 1.30001]" - @test sprint(show, MIME("text/plain"), b32) == "[-1.1755f-38, 1.30001f0]" - @test sprint(show, MIME("text/plain"), b16) == "[Float16(-6.104e-5), Float16(1.29981)]" + @test sprint(show, MIME("text/plain"), b) == "[-2.22508e-308, 1.3]" + @test sprint(show, MIME("text/plain"), b32) == "[-1.1755f-38, 1.3f0]" + @test_broken sprint(show, MIME("text/plain"), b16) == "[Float16(-6.104e-5), Float16(1.3)]" @test sprint(show, MIME("text/plain"), br) == "[-11//10, 13//10]" @test sprint(show, MIME("text/plain"), c) == "[-1.0, ∞)" - @test sprint(show, MIME("text/plain"), large_expo) == - "[0.0, 1.00001e+123456789]₂₅₆" + @test sprint(show, MIME("text/plain"), large_expo) == "[0.0, 1.0e+123456789]₂₅₆" end end @@ -107,13 +102,12 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "[1.0, 2.0]_com" @test sprint(show, MIME("text/plain"), a_NG) == "[1.0, 2.0]_com_NG" - @test sprint(show, MIME("text/plain"), b) == "[-2.2250738585072014e-308, 1.3000000000000000445]_com" - @test sprint(show, MIME("text/plain"), b32) == "[-1.1754944f-38, 1.2999999523162841797f0]_com" - @test sprint(show, MIME("text/plain"), b16) == "[Float16(-6.104e-5), Float16(1.2998046875000000001)]_com" + @test sprint(show, MIME("text/plain"), b) == "[-2.2250738585072014e-308, 1.3]_com" + @test sprint(show, MIME("text/plain"), b32) == "[-1.1754944f-38, 1.3f0]_com" + @test_broken sprint(show, MIME("text/plain"), b16) == "[Float16(-6.104e-5), Float16(1.3)]_com" @test sprint(show, MIME("text/plain"), br) == "[-11//10, 13//10]_com" @test sprint(show, MIME("text/plain"), c) == "[-1.0, ∞)_dac" - @test sprint(show, MIME("text/plain"), large_expo) == - "[0.0, 1.0000000000000000001e+123456789]₂₅₆_com" + @test sprint(show, MIME("text/plain"), large_expo) == "[0.0, 1.0e+123456789]₂₅₆_com" end end @@ -146,13 +140,12 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "(1.5 ± 0.5)_com" @test sprint(show, MIME("text/plain"), a_NG) == "(1.5 ± 0.5)_com_NG" - @test sprint(show, MIME("text/plain"), b) == "(0.65 ± 0.650001)_com" - @test sprint(show, MIME("text/plain"), b32) == "(0.65f0 ± 0.650001f0)_com" - @test sprint(show, MIME("text/plain"), b16) == "(Float16(0.649902) ± Float16(0.649903))_com" + @test sprint(show, MIME("text/plain"), b) == "(0.65 ± 0.65)_com" + @test_broken sprint(show, MIME("text/plain"), b32) == "(0.65f0 ± 0.65f0)_com" + @test_broken sprint(show, MIME("text/plain"), b16) == "(Float16(0.649902) ± Float16(0.65))_com" @test sprint(show, MIME("text/plain"), br) == "(1//10 ± 6//5)_com" @test sprint(show, MIME("text/plain"), c) == "(1.79769e+308 ± ∞)_dac" - @test sprint(show, MIME("text/plain"), large_expo) == - "(5.0e+123456788 ± 5.00001e+123456788)₂₅₆_com" + @test sprint(show, MIME("text/plain"), large_expo) == "(5.0e+123456788 ± 5.00001e+123456788)₂₅₆_com" end @testset "No decorations" begin @@ -163,13 +156,12 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "1.5 ± 0.5" @test sprint(show, MIME("text/plain"), a_NG) == "(1.5 ± 0.5)_NG" - @test sprint(show, MIME("text/plain"), b) == "0.65 ± 0.650001" - @test sprint(show, MIME("text/plain"), b32) == "0.65f0 ± 0.650001f0" - @test sprint(show, MIME("text/plain"), b16) == "Float16(0.649902) ± Float16(0.649903)" + @test sprint(show, MIME("text/plain"), b) == "0.65 ± 0.65" + @test_broken sprint(show, MIME("text/plain"), b32) == "0.65f0 ± 0.65f0" + @test_broken sprint(show, MIME("text/plain"), b16) == "Float16(0.649902) ± Float16(0.65)" @test sprint(show, MIME("text/plain"), br) == "1//10 ± 6//5" @test sprint(show, MIME("text/plain"), c) == "1.79769e+308 ± ∞" - @test sprint(show, MIME("text/plain"), large_expo) == - "(5.0e+123456788 ± 5.00001e+123456788)₂₅₆" + @test sprint(show, MIME("text/plain"), large_expo) == "(5.0e+123456788 ± 5.00001e+123456788)₂₅₆" end end end @@ -190,7 +182,7 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "[0.0, 2.0]_com + im*[1.0, 1.0]_com" @test sprint(show, MIME("text/plain"), b) == "[0.0, 2.0]_com - im*[1.0, 1.0]_com" - @test sprint(show, MIME("text/plain"), c) == "[0.0, 1.00001e-70]_com - im*[0.999999e-70, 1.00001e-70]_com" + @test sprint(show, MIME("text/plain"), c) == "[0.0, 1.0e-70]_com - im*[1.0e-70, 1.0e-70]_com" end @testset "No decorations" begin @@ -198,7 +190,7 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "[0.0, 2.0] + im*[1.0, 1.0]" @test sprint(show, MIME("text/plain"), b) == "[0.0, 2.0] - im*[1.0, 1.0]" - @test sprint(show, MIME("text/plain"), c) == "[0.0, 1.00001e-70] - im*[0.999999e-70, 1.00001e-70]" + @test sprint(show, MIME("text/plain"), c) == "[0.0, 1.0e-70] - im*[1.0e-70, 1.0e-70]" end end end @@ -209,7 +201,7 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "Interval{Float64}(0.0, 2.0, com) + im*Interval{Float64}(1.0, 1.0, com)" @test sprint(show, MIME("text/plain"), b) == "Interval{Float64}(0.0, 2.0, com) - im*Interval{Float64}(1.0, 1.0, com)" - # @test sprint(show, MIME("text/plain"), c) == "Interval{Float64}(0.0, 2.0, com) + im*Interval{Float64}(1.0, 1.0, com)" + @test sprint(show, MIME("text/plain"), c) == "Interval{Float64}(0.0, 1.0e-70, com) - im*Interval{Float64}(1.0e-70, 1.0e-70, com)" end @testset "Midpoint format" begin @@ -220,7 +212,7 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "(1.0 ± 1.0)_com + im*(1.0 ± 0.0)_com" @test sprint(show, MIME("text/plain"), b) == "(1.0 ± 1.0)_com - im*(1.0 ± 0.0)_com" - @test sprint(show, MIME("text/plain"), c) == "(5.0e-71 ± 5.00001e-71)_com - im*(1.0e-70 ± 0.0)_com" + @test sprint(show, MIME("text/plain"), c) == "(5.0e-71 ± 5.0e-71)_com - im*(1.0e-70 ± 0.0)_com" end @testset "No decorations" begin @@ -228,7 +220,7 @@ setprecision(BigFloat, 256) do @test sprint(show, MIME("text/plain"), a) == "(1.0 ± 1.0) + im*(1.0 ± 0.0)" @test sprint(show, MIME("text/plain"), b) == "(1.0 ± 1.0) - im*(1.0 ± 0.0)" - @test sprint(show, MIME("text/plain"), c) == "(5.0e-71 ± 5.00001e-71) - im*(1.0e-70 ± 0.0)" + @test sprint(show, MIME("text/plain"), c) == "(5.0e-71 ± 5.0e-71) - im*(1.0e-70 ± 0.0)" end end end diff --git a/test/interval_tests/set_operations.jl b/test/interval_tests/set_operations.jl index eed5e45a..dadf4eb7 100644 --- a/test/interval_tests/set_operations.jl +++ b/test/interval_tests/set_operations.jl @@ -1,17 +1,17 @@ using IntervalArithmetic: interval_diff -@testset "removed interval" begin - @test_throws ArgumentError intersect(interval(1)) - @test_throws ArgumentError intersect(interval(1), 2, [1], 4., 5) - @test_throws ArgumentError intersect(interval(1), interval(2.), interval(3.)) - @test_throws ArgumentError union(interval(1)) - @test_throws ArgumentError union(interval(1), 2, [1], 4., 5) - @test_throws ArgumentError union(interval(1), interval(2.), interval(3.)) - @test_throws ArgumentError setdiff(interval(1)) - @test_throws ArgumentError setdiff(interval(1), 2, [1], 4., 5) - @test_throws ArgumentError setdiff(interval(1), interval(2.), interval(3.)) - @test_throws ArgumentError symdiff(interval(1), interval(2.), interval(3.)) -end +# @testset "removed interval" begin +# @test_throws ArgumentError intersect(interval(1)) +# @test_throws ArgumentError intersect(interval(1), 2, [1], 4., 5) +# @test_throws ArgumentError intersect(interval(1), interval(2.), interval(3.)) +# @test_throws ArgumentError union(interval(1)) +# @test_throws ArgumentError union(interval(1), 2, [1], 4., 5) +# @test_throws ArgumentError union(interval(1), interval(2.), interval(3.)) +# @test_throws ArgumentError setdiff(interval(1)) +# @test_throws ArgumentError setdiff(interval(1), 2, [1], 4., 5) +# @test_throws ArgumentError setdiff(interval(1), interval(2.), interval(3.)) +# @test_throws ArgumentError symdiff(interval(1), interval(2.), interval(3.)) +# end @testset "interiordiff" begin x = interval(2, 4) @@ -57,4 +57,4 @@ end @test interval_diff(interval(1, 10), interval(-1, 14)) == [] @test interval_diff(interval(1, 10), interval(1, 10)) == [] -end \ No newline at end of file +end