FixedPointNumbers.jl
FixedPointNumbers.jl copied to clipboard
[Feature Request] shifting with << and >>
I would like to use <<
and >>
to shift bits of fixed point numbers.
For example, suppose x
is a fixed point, then I want
x >> 1
to be something like
reinterpret(typeof(x), reinterpret(Int, x) >> 1)
cf. #185
Currently, FixedPointNumbers does not support bitwise operations other than ~
.
Perhaps &
and |
should be manipulated in the raw type using reinterpret
, so that there is no ambiguity.
The same can be said for the bit shift operators. One of the ambiguity issues is about whether the decimal point should be shifted. In practice, however, this will not be so ambiguous. In my intuition, the decimal point will not shift, i.e., it is expected to keep the original type.
Another issue is that the multiplication and division for Integer
and FixedPoint
numbers are promoted to floating-point numbers (in FixedPointNumbers v0.9 series).
julia> 0.5Q0f7 / 2 # master i.e. the next v0.9 series
0.25f0
Often << 1
is associated with "twice", >> 1
with "half". However, confusing them with integer multiplication and division can easily lead to type instability problems.