Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] shifting with << and >> #250

Open
damtharvey opened this issue Jun 1, 2021 · 1 comment
Open

[Feature Request] shifting with << and >> #250

damtharvey opened this issue Jun 1, 2021 · 1 comment

Comments

@damtharvey
Copy link

damtharvey commented Jun 1, 2021

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)

@kimikage
Copy link
Collaborator

kimikage commented Jun 2, 2021

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.

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

No branches or pull requests

2 participants