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

Add bitwise operations with primitive ints #211

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

PatrickNorton
Copy link
Contributor

Fixes #205.

This does not add bitwise-or and bitwise-xor operations between signed integers and BigUint, because there is no good way to represent negative numbers with a BigUint (see #184). Bitwise-and operations were added because the result of such an operation will always be positive.

@cuviper
Copy link
Member

cuviper commented Aug 27, 2021

Bitwise-and operations were added because the result of such an operation will always be positive.

Just because we can, doesn't mean we should, and this would be the only operator that mixed BigUint with signed primitives.
(Well, except for shifts, but the standard library already set the precedent for that oddness...)

@PatrickNorton
Copy link
Contributor Author

You're right; I hadn't realized that the other operations would have such an issue until after I'd written the BitAnd implementation, and I figured it'd be better to ask before deleting it. I'll happily do so now if it doesn't make sense to include.

@Rudxain
Copy link

Rudxain commented Jul 11, 2022

Bitwise-and operations were added because the result of such an operation will always be positive

Correct me if I'm wrong, but ANDing -1 (as a BigInt) with any number (in two's complement) should be a no-op, therefore returning the original number with whatever sign it had before the operation. Does this library use another encoding other than two's complement? (sorry for this question, I'm new to Rust and this repo)

Update: wait I realized my mistake lol. The PR is about mixed-type bit ops, so a primitive -1 would have a finite popcount equal to its wordsize, therefore always returning an unsigned number

@cuviper
Copy link
Member

cuviper commented Feb 11, 2023

I still think the mixed signed-ness is too confusing, let's drop that.

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

Successfully merging this pull request may close these issues.

Add bitwise ops with primitive ints
3 participants