Skip to content

Support for non-standard integer types? #247

Description

@DrChainsaw

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions