Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Negative number support for big_int bit manipulations #5017
Original bug ID: 5017
The issue #4641 has added a basic bit manipulation functions to big_int library; very nice.
I feel that the current behavior of the shift operations for negative numbers are confusing; it seems to be better consistent with x * (2 ** y) and
Also, other bit manipulation functions for negative numbers can also be
I have an implementation using public interfaces of Nat and Big_int;
Comment author: @xavierleroy
After thinking about it, I agree that it is better for right shifts on negative numbers to behave like Euclidean division by 2^n, i.e. round towards minus infinity. Adjusted the behavior of shift_right_big_int accordingly. The old behavior is available as function shift_right_towards_zero_big_int. All this will be in release 3.12.0.
Concerning and, or and xor on negative numbers, an efficient implementation that minimizes allocation of temporary nats is quite complex indeed, so I'd rather not do it immediately. I'll keep this in mind for later.