Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Float16 setrounding error #486

Closed
AnderGray opened this issue Aug 24, 2021 · 2 comments · Fixed by #593
Closed

Float16 setrounding error #486

AnderGray opened this issue Aug 24, 2021 · 2 comments · Fixed by #593

Comments

@AnderGray
Copy link

Does anyone know why this is happening?

using IntervalArithmetic

a = interval(Float16(1.0), Float16(3.0))
a + a

gives:

ERROR: MethodError: no method matching rounding_raw(::Type{Float16})
Closest candidates are:
  rounding_raw(::Type{BigFloat}) at mpfr.jl:121
  rounding_raw(::Type{var"#s79"} where var"#s79"<:Union{Float32, Float64}) at rounding.jl:155
Stacktrace:
 [1] setrounding(f::IntervalArithmetic.var"#11#12"{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/UR6Qe/src/intervals/rounding.jl:177
 [3] +(a::Float16, b::Float16, r::RoundingMode{:Down})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/UR6Qe/src/intervals/rounding.jl:278
 [4] +(a::Interval{Float16}, b::Interval{Float16})
   @ IntervalArithmetic ~/.julia/packages/IntervalArithmetic/UR6Qe/src/intervals/arithmetic.jl:86
 [5] top-level scope
   @ REPL[5]:1

I get the same error when:

lo = Float16(1)
hi = Float16(3)

out = setrounding(Float16, RoundDown) do
	collect(range(lo, hi, length = 10))
end

giving:

ERROR: MethodError: no method matching rounding_raw(::Type{Float16})
Closest candidates are:
  rounding_raw(::Type{BigFloat}) at mpfr.jl:121
  rounding_raw(::Type{var"#s79"} where var"#s79"<:Union{Float32, Float64}) at rounding.jl:155
Stacktrace:
 [1] setrounding(f::var"#1#2", #unused#::Type{Float16}, rounding::RoundingMode{:Down})
   @ Base.Rounding ./rounding.jl:173
 [2] top-level scope
   @ REPL[8]:1
@lucaferranti
Copy link
Member

I think that's because the setrounding function does not support 16 bits floating points. A work around could be to use the accurate rounding mode, which uses prevfloat and nextfloat internally after each operation. This would not necessarily be tight though.

julia> setrounding(Interval, :accurate)
:accurate

julia> a + a
[1.99902, 6.00391]

@lucaferranti
Copy link
Member

On the other hand, the default rounding mode :tight should not be using setrounding at all, but the RoundingEmulator.jl package which uses error-free transformations. @dpsanders isn't it so, or am I missing something?

@OlivierHnt OlivierHnt mentioned this issue Dec 11, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants