Pack of (- 2^31-1) is wrong #42

maxtaco opened this Issue Feb 26, 2013 · 1 comment


None yet

2 participants

maxtaco commented Feb 26, 2013

In Python:

from struct import *
pack('q', -2147483649)

will yield \xff\xff\xff\x7f\xff\xff\xff\xff

Which is what I'd expected too (the Big Endian two's complement of -2147483649 )

Also, the Python msgpack library gets it right:

import msgpack

Yields: \xd3\xff\xff\xff\xff\x7f\xff\xff\xff

Here's how it works with the Node purepack module (which I maintain and use msgpack to test against):

pp = require 'purepack'
pp.pack(-2147483649, 'buffer')
<Buffer d3 ff ff ff ff 7f ff ff ff>

I had to jump through some hoops to get this working in pure JavaScript, I'm not sure if there's a better way with the V8 extension method...

@maxtaco maxtaco added a commit to maxtaco/node-msgpack that referenced this issue Feb 26, 2013
@maxtaco maxtaco This fixes Issue #42 and puts in at least one regression test for 64-bit
integer values, which work in node.js up to about 2^54 and down to
-2^54. May as well make a best effort to get them right.  This issue is
due to a regression introduced in commits  6b4c80c and 0b4f361, which
taken together always encode larger integers as doubles, even when
they shouldn't be.

Merged the pull request to fix this.

@godsflaw godsflaw closed this Jun 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment