Skip to content

Negative number of fractional bits #311

@PatrickHaecker

Description

@PatrickHaecker

With Fixed we can reduce the number of fractional bits to trade range for precision:

julia> Fixed{Int8, 2} .|> (typemin, typemax, eps)
(-32.0Q5f2, 31.75Q5f2, 0.25Q5f2)

julia> Fixed{Int8, 1} .|> (typemin, typemax, eps)
(-64.0Q6f1, 63.5Q6f1, 0.5Q6f1)

julia> Fixed{Int8, 0} .|> (typemin, typemax, eps)
(-128.0Q7f0, 127.0Q7f0, 1.0Q7f0)

However, currently support stops here. It would be useful to have a

julia> Fixed{Int8, -1} .|> (typemin, typemax, eps)
(-256.0Q8f-1, 255.0Q8f-1, 2.0Q8f-1)

and all the other types with a negative number of fractional bits available, when range demands are high, precision demands are low and you want to distribute the available values uniformly in the range or want to use integer arithmetic (so floating points are not an option).

This would not really match the packet's name as they are not really fixed-point numbers (with the "point" being outside of the represented bits). On the other hand, an implementation of these numbers (scaled integers) seems to be completely identical in representing the type (struct) and should cover both positive and negative numbers of fractional bits if some methods are generalized or their domain restrictions are relaxed.

So what would these scaled integers be? Would they use a slightly generalized version of Fixed, would they be a ScaledInteger within the FixedPointNumbers.jl package or would they be the topic of a ScaledIntegers.jl package?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions