dzhang314 / MultiFloats.jl

Fast, SIMD-accelerated extended-precision arithmetic for Julia
MIT License
77 stars 10 forks source link

Missing methods in conversion to Integer #20

Closed jishnub closed 1 month ago

jishnub commented 3 years ago
julia> Int(Float64x4(3.0))
ERROR: MethodError: no method matching Int64(::MultiFloat{Float64, 4})
Closest candidates are:
  (::Type{T})(::T) where T<:Number at boot.jl:760
  (::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  (::Type{T})(::BigInt) where T<:Union{Int128, Int16, Int32, Int64, Int8} at gmp.jl:356
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[37]:1

julia> Integer(Float64x4(3.0))
ERROR: MethodError: no method matching Integer(::MultiFloat{Float64, 4})
Closest candidates are:
  (::Type{T})(::T) where T<:Number at boot.jl:760
  (::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  (::Type{T})(::Base.TwicePrecision) where T<:Number at twiceprecision.jl:243
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[38]:1

It would be nice for these to work to easily switch between Float64 and MultiFloats.

dzhang314 commented 1 month ago

Hey @jishnub! Thanks for your interest in MultiFloats.jl, and sorry I never got around to looking at this issue years ago.

I've added a conversion to Integer that goes through BigFloat in commit 7eb21d6. Is this sufficient for your purposes? It might be possible to get a faster version that doesn't go through BigFloat, but I don't really understand the use-case of conversion to Integer when it only works for a vanishingly small fraction of inputs.

If this stopgap solution is insufficient, please feel free to reopen this issue.