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

Bitwise methods #281

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

Bitwise methods #281

wants to merge 21 commits into from

Conversation

Vap0r1ze
Copy link

Hiya Mike, It's me from #106 I'm opening a fresh PR since I deleted my old fork. I believe I addressed all of your concerns, but it's pretty late so I wouldn't be surprised if I missed something. Let me know what else there is to be done, or any issues you have with the PR in its current state.

@MikeMcl
Copy link
Owner

MikeMcl commented Dec 29, 2020

Hello again.
I'll take a look at this properly this weekend.

@MikeMcl
Copy link
Owner

MikeMcl commented Dec 29, 2020

A quick first test of bitShiftRight seems to give the wrong answer:

let n = new BigNumber(4);
n = n.bitShiftRight(1);
console.log(n.toString());    // '4'
console.log(4 >> 1);          // 2

@Vap0r1ze
Copy link
Author

fixed that

@MikeMcl
Copy link
Owner

MikeMcl commented Jan 1, 2021

console.log(BigNumber(9).and(57).toString());     // 2
console.log(9 & 57);                              // 9

console.log(BigNumber(8).or(38).toString());      // 11
console.log(8 | 38);                              // 46

console.log(BigNumber(34).xor(89).toString());    // 61 
console.log(34 ^ 89);                             // 123

console.log(BigNumber(84).not().toString());      // NaN 
console.log(~84);                                 // -85

@Vap0r1ze
Copy link
Author

Vap0r1ze commented Jan 2, 2021

oh i forgot tests, that would be important

@pwener
Copy link

pwener commented Oct 20, 2021

Hello, can I help this feature?

@Vap0r1ze
Copy link
Author

Vap0r1ze commented Oct 21, 2021

Hello, can I help this feature?

Yea I think you'd just need to write tests dealing with all the methods dealing with special cases too for replicating the behaviour of >> and <<. Afterwards just bug fix from there.

Edit: Feel free to open PR over at Vap0r1ze:bitwise :D

@pwener
Copy link

pwener commented Nov 4, 2021

Hi everyone, I submitted an PR at Vap0r1ze:bitwise . I have a doubt, that you can answer too @MikeMcl , we can put all these test together in the same file?

@pwener
Copy link

pwener commented Oct 26, 2022

@MikeMcl there is some issue here?

@MikeMcl
Copy link
Owner

MikeMcl commented Oct 26, 2022

Yes.

BigInt(-3) & BigInt(4)    // 4n

BigNumber(-3).and(4).toString()    // '0'

BigNumber bitiwse operations need to match BigInt.

It's been a while since I looked at this but I remember working on it a bit and getting the results to match but I wasn't happy with the performance due to it using string operations and applying native bitwise ops one bit at a time.

I currently have:

bignumber.zip

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.

None yet

3 participants