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

buf() mishandles [3, 0, 0, 0, 0] #9

Closed
FGasper opened this issue Oct 15, 2017 · 4 comments
Closed

buf() mishandles [3, 0, 0, 0, 0] #9

FGasper opened this issue Oct 15, 2017 · 4 comments

Comments

@FGasper
Copy link

FGasper commented Oct 15, 2017

> const CRC32_MOD = require('crc-32');
undefined
> CRC32_MOD.buf([3, 0, 0, 0, 0])
-2122150451
>
@FGasper
Copy link
Author

FGasper commented Oct 15, 2017

Never mind … I didn’t realize this computes a signed value rather than unsigned.

@FGasper FGasper closed this as completed Oct 15, 2017
@reviewher
Copy link

"The return value is a signed 32-bit integer."

See the discussion from an older issue. Basically V8 has a special optimization for 32-bit signed integers which is generally awesome but performs extremely poorly for naive CRC calculations

@FGasper
Copy link
Author

FGasper commented Oct 15, 2017

Might be nice to include a convenience that does the signed-to-unsigned conversion?

I think it's just: 0xffffffff - ~signed?

@reviewher
Copy link

Even easier: signed >>> 0 :) kinda seems like a waste to add that as a convenience method, but it's probably worth adding that to the README (PRs welcome)

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

No branches or pull requests

2 participants