pierrec / js-cuint

C-like unsigned integers for Javascript
MIT License
32 stars 9 forks source link

De-alias `not` from `negate`, make `not` mean bitwise NOT #1

Closed tec27 closed 9 years ago

tec27 commented 9 years ago

I was using this library for a small project that involved the conversion of a reverse-engineered encryption algorithm from C to JS. Upon writing the same basic code as the C version, using this library to implement all the arithmetic, I noticed that the output was different than the known-good version. I spent a bit debugging my own code, assuming that to be the problem, then finally gave up and thought it must be a bug in something in this library. After stepping through the JS and C version step-by-step, I noticed that it was actually a much simpler problem: the UINT#not() method was not at all what I had expected it to be!

I realize the documentation declared that this was an alias for negate, but I think most people would probably blindly assume this maps to Javascript's ~ operator, rather than unary -. This PR adds a new implementation to UINT32 and UINT64 for UINT#not() only, leaving the old negate implementation intact, and updates the documentation to match. There's also a separate commit that fixes a slight issue in the dependency list that made it hard to run tests.