Comparing version 0.14.2 to 0.15.0
@@ -287,3 +287,3 @@ // Utils | ||
BN.prototype.toString = function toString(base) { | ||
BN.prototype.toString = function toString(base, padding) { | ||
base = base || 10; | ||
@@ -293,2 +293,3 @@ if (base === 16 || base === 'hex') { | ||
var off = 0; | ||
var padding = padding | 0 || 1; | ||
var carry = 0; | ||
@@ -311,2 +312,4 @@ for (var i = 0; i < this.length; i++) { | ||
out = carry.toString(16) + out; | ||
while (out.length % padding !== 0) | ||
out = '0' + out; | ||
if (this.sign) | ||
@@ -313,0 +316,0 @@ out = '-' + out; |
{ | ||
"name": "bn.js", | ||
"version": "0.14.2", | ||
"version": "0.15.0", | ||
"description": "Big number implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/bn.js", |
@@ -73,2 +73,38 @@ var assert = require('assert'); | ||
describe('hex padding', function(){ | ||
it('should have length of 8 from leading 15', function(){ | ||
var a = new BN('ffb9602', 16); | ||
var b = new Buffer(a.toString('hex', 2), 'hex'); | ||
assert.equal(a.toString('hex', 2).length, 8); | ||
}); | ||
it('should have length of 8 from leading zero', function(){ | ||
var a = new BN('fb9604', 16); | ||
var b = new Buffer(a.toString('hex', 8), 'hex'); | ||
assert.equal(a.toString('hex', 8).length, 8); | ||
}); | ||
it('should have length of 8 from leading zeros', function(){ | ||
var a = new BN(0); | ||
var b = new Buffer(a.toString('hex', 8), 'hex'); | ||
assert.equal(a.toString('hex', 8).length, 8); | ||
}); | ||
it('should have length of 64 from leading 15', function(){ | ||
var a = new BN( | ||
'ffb96ff654e61130ba8422f0debca77a0ea74ae5ea8bca9b54ab64aabf01003', | ||
16); | ||
var b = new Buffer(a.toString('hex', 2), 'hex'); | ||
assert.equal(a.toString('hex', 2).length, 64); | ||
}); | ||
it('should have length of 64 from leading zero', function(){ | ||
var a = new BN( | ||
'fb96ff654e61130ba8422f0debca77a0ea74ae5ea8bca9b54ab64aabf01003', | ||
16); | ||
var b = new Buffer(a.toString('hex', 64), 'hex'); | ||
assert.equal(a.toString('hex', 64).length, 64); | ||
}); | ||
}); | ||
describe('iaddn', function() { | ||
@@ -75,0 +111,0 @@ it('should allow a sign change', function() { |
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
63234
2052