Closed Vap0r1ze closed 1 month ago
Hello again. I'll take a look at this properly this weekend.
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
fixed that
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
oh i forgot tests, that would be important
Hello, can I help this feature?
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
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?
@MikeMcl there is some issue here?
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:
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.