{"name":"node-int64","description":"Support for representing 64-bit integers in JavaScript","url":"http://github.com/broofa/node-int64","keywords":["math","integer","int64"],"author":{"name":"Robert Kieffer","email":"robert@broofa.com"},"contributors":[],"dependencies":{},"license":"MIT","lib":".","main":"./Int64.js","version":"0.4.0","scripts":{"test":"nodeunit test.js"},"repository":{"type":"git","url":"https://github.com/broofa/node-int64"},"devDependencies":{"nodeunit":"^0.9.0"},"gitHead":"c1567475712cb1cfe100c96813c2a2a92e2b42ce","bugs":{"url":"https://github.com/broofa/node-int64/issues"},"homepage":"https://github.com/broofa/node-int64","_id":"node-int64@0.4.0","_shasum":"87a9065cdb355d3182d8f94ce11188b825c68a3b","_from":".","_npmVersion":"1.4.28","_npmUser":{"name":"broofa","email":"robert@broofa.com"},"maintainers":[{"name":"broofa","email":"robert@broofa.com"}],"dist":{"shasum":"87a9065cdb355d3182d8f94ce11188b825c68a3b","tarball":"http://registry-npm.ywwl.com/node-int64/download/node-int64-0.4.0.tgz","integrity":"sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDfg4kjKAf8n+lW22IaEScPlFzwmL/aUAGYvm4EfJGwVAiEAlWDIudaBo4CVef834sQL/82VP6kUbImYrwY9g5QpRVw="}],"size":6059,"noattachment":false,"key":"/node-int64/-/node-int64-0.4.0.tgz"},"directories":{},"readme":"JavaScript Numbers are represented as [IEEE 754 double-precision floats](http://steve.hollasch.net/cgindex/coding/ieeefloat.html).  Unfortunately, this means they lose integer precision for values beyond +/- 2^^53.  For projects that need to accurately handle 64-bit ints, such as [node-thrift](https://github.com/wadey/node-thrift), a performant, Number-like class is needed.  Int64 is that class.\n\nInt64 instances look and feel much like JS-native Numbers.  By way of example ...\n```js\n// First, let's illustrate the problem ...\n> (0x123456789).toString(16)\n'123456789' // <- what we expect.\n> (0x123456789abcdef0).toString(16)\n'123456789abcdf00' // <- Ugh!  JS doesn't do big ints. :(\n\n// So let's create a couple Int64s using the above values ...\n\n// Require, of course\n> Int64 = require('node-int64')\n\n// x's value is what we expect (the decimal value of 0x123456789)\n> x = new Int64(0x123456789)\n[Int64 value:4886718345 octets:00 00 00 01 23 45 67 89]\n\n// y's value is Infinity because it's outside the range of integer\n// precision.  But that's okay - it's still useful because it's internal\n// representation (octets) is what we passed in\n> y = new Int64('123456789abcdef0')\n[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]\n\n// Let's do some math.  Int64's behave like Numbers.  (Sorry, Int64 isn't\n// for doing 64-bit integer arithmetic (yet) - it's just for carrying\n// around int64 values\n> x + 1\n4886718346\n> y + 1\nInfinity\n\n// Int64 string operations ...\n> 'value: ' + x\n'value: 4886718345'\n> 'value: ' + y\n'value: Infinity'\n> x.toString(2)\n'100100011010001010110011110001001'\n> y.toString(2)\n'Infinity'\n\n// Use JS's isFinite() method to see if the Int64 value is in the\n// integer-precise range of JS values\n> isFinite(x)\ntrue\n> isFinite(y)\nfalse\n\n// Get an octet string representation.  (Yay, y is what we put in!)\n> x.toOctetString()\n'0000000123456789'\n> y.toOctetString()\n'123456789abcdef0'\n\n// Finally, some other ways to create Int64s ...\n\n// Pass hi/lo words\n> new Int64(0x12345678, 0x9abcdef0)\n[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]\n\n// Pass a Buffer\n> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]))\n[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]\n\n// Pass a Buffer and offset\n> new Int64(new Buffer([0,0,0,0,0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0]), 4)\n[Int64 value:Infinity octets:12 34 56 78 9a bc de f0]\n\n// Pull out into a buffer\n> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).toBuffer()\n<Buffer 12 34 56 78 9a bc de f0>\n\n// Or copy into an existing one (at an offset)\n> var buf = new Buffer(1024);\n> new Int64(new Buffer([0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0])).copy(buf, 512);\n```\n","publish_time":1428115936354,"_cnpm_publish_time":1428115936354,"dist-tags":{"latest":"0.4.0"}}