JuliaMath / JuliaMath/FixedPointNumbers.jl

Support for non-standard integer types?

Open
#247 4 comments 2 reactions 0 assignees View on GitHub
add-on enhancement
Dominant language
Julia
Stars
95
Forks
38
Avg merge
13m
Merged PRs (30d)
2

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
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.