bigint-browserify
Advanced tools
Comparing version 0.0.1 to 0.0.2
21
index.js
@@ -24,2 +24,22 @@ var jsbn = require('jsbn'); | ||
}, | ||
eq: function(a) { | ||
if (!a._jsbn) a = new BigInt(a); | ||
return this._jsbn.equals(a._jsbn); | ||
}, | ||
cmp: function(a) { | ||
if (!a._jsbn) a = new BigInt(a); | ||
return this._jsbn.compareTo(a._jsbn); | ||
}, | ||
gt: function(a) { | ||
return this.cmp(a) > 0; | ||
}, | ||
ge: function(a) { | ||
return this.cmp(a) >= 0; | ||
}, | ||
lt: function(a) { | ||
return this.cmp(a) < 0; | ||
}, | ||
le: function(a) { | ||
return this.cmp(a) <= 0; | ||
}, | ||
bitLength: function() { | ||
@@ -30,2 +50,3 @@ return this._jsbn.bitLength(); | ||
var hex = this._jsbn.toString(16); | ||
if (hex.length % 2) hex = '0' + hex; | ||
return new Buffer(hex, 'hex'); | ||
@@ -32,0 +53,0 @@ }, |
{ | ||
"name": "bigint-browserify", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "bigint api for browser javascript", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -22,2 +22,4 @@ var test = require("tape"); | ||
// operations | ||
['add', 'sub', 'mul', 'mod', 'xor', 'powm'] | ||
@@ -40,2 +42,28 @@ .forEach(function(name) { | ||
// comparisons | ||
assertSame('eq', function(bigint, cb) { | ||
var ba = bigint(a, 16); | ||
var bb = bigint(b, 16); | ||
cb(null, ba.eq(bb) && ba.eq(ba)); | ||
}); | ||
['cmp', 'gt', 'ge', 'lt', 'le'] | ||
.forEach(function(name) { | ||
assertSame(name, function(bigint, cb) { | ||
var ba = bigint(a, 16); | ||
var bb = bigint(b, 16); | ||
cb(null, ba[name](bb) && bb[name](ba) && ba[name](ba)); | ||
}); | ||
assertSame('bigint.' + name, function(bigint, cb) { | ||
var ba = bigint(a, 16); | ||
var bb = bigint(b, 16); | ||
cb(null, bigint[name](ba, bb) && bigint[name](bb, ba) && bigint[name](ba, ba)); | ||
}); | ||
}); | ||
// misc | ||
assertSame('bitLength', function(bigint, cb) { | ||
@@ -42,0 +70,0 @@ var ba = bigint(a, 16); |
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
4577
145