JeffreySarnoff / SaferIntegers.jl

These integer types use checked arithmetic, otherwise they are as system types.
MIT License
59 stars 9 forks source link

Conversion via float #19

Closed mkitti closed 3 years ago

mkitti commented 3 years ago

Could we extend Base.float to work with SaferIntegers?

julia> using SaferIntegers

julia> float(SafeInt(3))
ERROR: MethodError: no method matching AbstractFloat(::SafeInt64)
Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:200
  (::Type{T})(::T) where T<:Number at boot.jl:760
  (::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  ...
Stacktrace:
 [1] float(x::SafeInt64)
   @ Base .\float.jl:206
 [2] top-level scope
   @ REPL[2]:1

julia> Base.float(x::SafeInteger) = Base.float(SaferIntegers.baseint(x))

julia> float(SafeInt(3))
3.0
mkitti commented 3 years ago

x.f. https://github.com/JuliaMath/Interpolations.jl/issues/457

mkitti commented 3 years ago

Fixed by 8eec6df6