IntervalArithmetic.jl icon indicating copy to clipboard operation
IntervalArithmetic.jl copied to clipboard

Improve `Float32` support

Open dpsanders opened this issue 5 years ago • 7 comments

Interval{Float32} support is very patchy, c.f. e.g. #414

Float16 is less useful since arithmetic operations on Float16 just promote to Float32 anyway.

dpsanders avatar Sep 21 '20 16:09 dpsanders

Couldn't tests be written to enforce a Float32 (and a Float8 and Float16 "just in case") support? By that I mean rewriting most tests using for loops on types. https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/a1cbb81223e350a23b6d03f0de9456734b88a982/test/interval_tests/bisect.jl#L1-L32 would became

using IntervalArithmetic
using Test


@testset "`bisect` function" begin
    FloatTypes = [Float8, Float16, Float32, Float64]
    for T in FloatTypes
        X = 0..1
        @test bisect(X, T(0.5)) == (T(0)..T(0.5), T(0.5)..T(1))
        @test bisect(X, T(0.25)) == (T(0)..T(0.25), T(0.25)..T(1))

        @test bisect(X) == (interval(T(0.0), T(0.49609375)), interval(T(0.49609375), T(1.0)))

        # [...]
    end
end

remi-garcia avatar Sep 21 '20 16:09 remi-garcia

Yes that's a great idea. (Note that Float8 doesn't exist.)

dpsanders avatar Sep 21 '20 17:09 dpsanders

With julia 1.6.7

julia> interval(Float16(1))/interval(Float16(0.1))
ERROR: MethodError: no method matching rounding_raw(::Type{Float16})
Closest candidates are:
  rounding_raw(::Type{BigFloat}) at mpfr.jl:121
  rounding_raw(::Type{var"#s77"} where var"#s77"<:Union{Float32, Float64}) at rounding.jl:155
Stacktrace:
 [1] setrounding(f::IntervalArithmetic.var"#29#30"{Float16, Float16}, #unused#::Type{Float16}, rounding::RoundingMode{:Down})
   @ Base.Rounding ./rounding.jl:173
 [2] /(#unused#::IntervalArithmetic.IntervalRounding{:tight}, a::Float16, b::Float16, #unused#::RoundingMode{:Down})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/EquAX/src/intervals/rounding.jl:177
 [3] /(a::Float16, b::Float16, r::RoundingMode{:Down})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/EquAX/src/intervals/rounding.jl:278
 [4] /(a::Interval{Float16}, b::Interval{Float16})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/EquAX/src/intervals/arithmetic.jl:183
 [5] top-level scope
   @ REPL[16]:1

Works with julia 1.10.2

remi-garcia avatar Apr 16 '24 13:04 remi-garcia

What version of IntervalArithmetic are you using? (I guess it is not v0.22.11, since it restricts to using Julia 1.9 or above)

lbenet avatar Apr 16 '24 15:04 lbenet

  [d1acc4aa] IntervalArithmetic v0.20.9

With julia LTS (1.6.7), this package cannot be updated.

remi-garcia avatar Apr 16 '24 20:04 remi-garcia

As mentioned, to use more recent versions (which I believe solved the problem reported) you need at least Julia v1.9; I suggest to upgrade to Julia 1.10...

lbenet avatar Apr 17 '24 00:04 lbenet

Yeah, I saw that with julia 1.10.2 and IntervalArithmetic v0.22.11 it works. Just giving some more info on this issue.

remi-garcia avatar Apr 17 '24 06:04 remi-garcia