-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Labels
Description
Sorry if this is naive, but would it be possible to support fixed point representations of non-standard integer sizes? It looks like it would be a simple thing to fix:
Example:
julia> using FixedPointNumbers, BitIntegers
julia> BitIntegers.@define_integers 24;
julia> sizeof(Int24)
3
julia> sizeof(Fixed{Int24, 2}) # I think this is what causes reinterpret below to fail
4
julia> reinterpret(Fixed{Int24, 2}, UInt8.(1:3))
ERROR: ArgumentError: cannot reinterpret an `UInt8` array to `Fixed{Int24, 2}` whose first dimension has size `3`.
The resulting array would have non-integral first dimension.
Stacktrace:
[1] (::Base.var"#thrownonint#243")(S::Type, T::Type, dim::Int64)
@ Base ./reinterpretarray.jl:27
[2] reinterpret(#unused#::Type{Fixed{Int24, 2}}, a::Vector{UInt8})
@ Base ./reinterpretarray.jl:42
[3] top-level scope
@ REPL[8]:1
julia> Base.sizeof(::Type{<:Fixed{Int24}}) = 3
# This stuff below is correct, right?
julia> reinterpret(Fixed{Int24, 0}, UInt8.(1:3))
1-element reinterpret(Fixed{Int24, 0}, ::Vector{UInt8}):
197121.0Q23f0
julia> reinterpret(Int24, UInt8.(1:3))
1-element reinterpret(Int24, ::Vector{UInt8}):
197121
julia> reinterpret(Fixed{Int24, 1}, UInt8.(1:3))
1-element reinterpret(Fixed{Int24, 1}, ::Vector{UInt8}):
98560.5Q22f1
julia> reinterpret(Int24, UInt8.(1:3)) / 2
1-element Vector{Float64}:
98560.5
kimikage and chrisvwx