Comparing version 0.1.1 to 0.1.2
49
index.js
@@ -0,1 +1,3 @@ | ||
var arrayCopy = require('./lib/arraycopy'); | ||
module.exports = BigInt; | ||
@@ -7,3 +9,2 @@ | ||
BASE = 1 << BITS, | ||
MASK = BASE - 1, | ||
DECIMAL_SHIFT = 4, | ||
@@ -37,43 +38,3 @@ DECIMAL_BASE = 10000; | ||
} else if (Array.isArray(opt_value)) { | ||
var numItems = opt_value.length; | ||
if (!opt_bitsPerItem) opt_bitsPerItem = 8; | ||
if (opt_bitsPerItem < 1 || opt_bitsPerItem > 32) { | ||
throw new Error('Bits per item must be in range 1–32'); | ||
} | ||
var totalBits = numItems * opt_bitsPerItem; | ||
digits = new Uint16Array(Math.ceil(totalBits / BITS)); | ||
var index = 0, | ||
bits = totalBits % BITS || BITS; | ||
for (var i = 0; i < numItems; i++) { | ||
var value = opt_value[i]; | ||
var overflow = opt_bitsPerItem - bits; | ||
if (overflow < 0) { | ||
digits[index] |= value << -overflow >>> 0 & MASK; | ||
} else { | ||
digits[index] |= value >>> overflow & MASK; | ||
} | ||
while (overflow > 0) { | ||
index++; | ||
if (overflow < BITS) { | ||
digits[index] = value << (BITS - overflow) >>> 0 & MASK; | ||
} else { | ||
digits[index] = value >>> (overflow - BITS) & MASK; | ||
} | ||
overflow -= BITS; | ||
} | ||
bits -= opt_bitsPerItem; | ||
while (bits < 0) bits += BITS; | ||
} | ||
digits = arrayCopy(opt_value, opt_bitsPerItem || 8, BITS); | ||
this.negative = false; | ||
@@ -116,2 +77,6 @@ } | ||
BigInt.prototype.toBytes = function (opt_destArray) { | ||
return arrayCopy(this.digits, BITS, 8, opt_destArray); | ||
}; | ||
BigInt.prototype.toJSON = function () { | ||
@@ -118,0 +83,0 @@ return this.valueOf(); |
{ | ||
"name": "bigintjs", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Allows working with integers of any size.", | ||
@@ -16,4 +16,8 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "vows test/* --spec" | ||
}, | ||
"devDependencies": { | ||
"assert": "^1.1.1", | ||
"vows": "~0.7.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
BigInt | ||
BigInt [![Build Status Image][]][Build Status] | ||
====== | ||
@@ -48,2 +48,4 @@ | ||
[Browserify]: http://browserify.org/ | ||
[Build Status]: https://travis-ci.org/blixt/js-bigint | ||
[Build Status Image]: https://api.travis-ci.org/blixt/js-bigint.png?branch=master | ||
[NPM]: https://www.npmjs.org/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
8261
8
212
2
51
2