Comparing version 1.2.4 to 1.3.0
109
lib/bn.js
@@ -497,2 +497,111 @@ (function(module, exports) { | ||
// Or `num` with `this` in-place | ||
BN.prototype.ior = function ior(num) { | ||
this.sign = this.sign || num.sign; | ||
while (this.length < num.length) | ||
this.words[this.length++] = 0; | ||
for (var i = 0; i < num.length; i++) | ||
this.words[i] = this.words[i] | num.words[i]; | ||
return this.strip(); | ||
}; | ||
// Or `num` with `this` | ||
BN.prototype.or = function or(num) { | ||
if (this.length > num.length) | ||
return this.clone().ior(num); | ||
else | ||
return num.clone().ior(this); | ||
}; | ||
// And `num` with `this` in-place | ||
BN.prototype.iand = function iand(num) { | ||
this.sign = this.sign && num.sign; | ||
// b = min-length(num, this) | ||
var b; | ||
if (this.length > num.length) | ||
b = num; | ||
else | ||
b = this; | ||
for (var i = 0; i < b.length; i++) | ||
this.words[i] = this.words[i] & num.words[i]; | ||
this.length = b.length; | ||
return this.strip(); | ||
}; | ||
// And `num` with `this` | ||
BN.prototype.and = function and(num) { | ||
if (this.length > num.length) | ||
return this.clone().iand(num); | ||
else | ||
return num.clone().iand(this); | ||
}; | ||
// Xor `num` with `this` in-place | ||
BN.prototype.ixor = function ixor(num) { | ||
this.sign = this.sign || num.sign; | ||
// a.length > b.length | ||
var a; | ||
var b; | ||
if (this.length > num.length) { | ||
a = this; | ||
b = num; | ||
} else { | ||
a = num; | ||
b = this; | ||
} | ||
for (var i = 0; i < b.length; i++) | ||
this.words[i] = a.words[i] ^ b.words[i]; | ||
if (this !== a) | ||
for (; i < a.length; i++) | ||
this.words[i] = a.words[i]; | ||
this.length = a.length; | ||
return this.strip(); | ||
}; | ||
// Xor `num` with `this` | ||
BN.prototype.xor = function xor(num) { | ||
if (this.length > num.length) | ||
return this.clone().ixor(num); | ||
else | ||
return num.clone().ixor(this); | ||
}; | ||
// Set `bit` of `this` | ||
BN.prototype.setn = function setn(bit, val) { | ||
assert(typeof bit === 'number' && bit >= 0); | ||
var off = (bit / 26) | 0; | ||
var wbit = bit % 26; | ||
while (this.length <= off) | ||
this.words[this.length++] = 0; | ||
if (val) | ||
this.words[off] = this.words[off] | (1 << wbit); | ||
else | ||
this.words[off] = this.words[off] & ~(1 << wbit); | ||
return this.strip(); | ||
}; | ||
// Add `num` to `this` in-place | ||
@@ -499,0 +608,0 @@ BN.prototype.iadd = function iadd(num) { |
{ | ||
"name": "bn.js", | ||
"version": "1.2.4", | ||
"version": "1.3.0", | ||
"description": "Big number implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/bn.js", |
@@ -9,3 +9,3 @@ # bn.js [![Build Status](https://secure.travis-ci.org/indutny/bn.js.png)](http://travis-ci.org/indutny/bn.js) | ||
Copyright Fedor Indutny, 2014. | ||
Copyright Fedor Indutny, 2015. | ||
@@ -12,0 +12,0 @@ Permission is hereby granted, free of charge, to any person obtaining a |
@@ -448,2 +448,60 @@ var assert = require('assert'); | ||
}); | ||
it('should and numbers', function () { | ||
assert.equal(new BN('1010101010101010101010101010101010101010', 2) | ||
.and(new BN('101010101010101010101010101010101010101', 2)) | ||
.toString(2), '0'); | ||
}); | ||
it('should iand numbers', function () { | ||
assert.equal(new BN('1010101010101010101010101010101010101010', 2) | ||
.iand(new BN('101010101010101010101010101010101010101', 2)) | ||
.toString(2), '0'); | ||
assert.equal(new BN('1000000000000000000000000000000000000001', 2) | ||
.iand(new BN('1', 2)) | ||
.toString(2), '1') | ||
assert.equal(new BN('1', 2) | ||
.iand(new BN('1000000000000000000000000000000000000001', 2)) | ||
.toString(2), '1') | ||
}); | ||
it('should or numbers', function () { | ||
assert.equal(new BN('1010101010101010101010101010101010101010', 2) | ||
.or(new BN('101010101010101010101010101010101010101', 2)) | ||
.toString(2), '1111111111111111111111111111111111111111'); | ||
}); | ||
it('should ior numbers', function () { | ||
assert.equal(new BN('1010101010101010101010101010101010101010', 2) | ||
.ior(new BN('101010101010101010101010101010101010101', 2)) | ||
.toString(2), '1111111111111111111111111111111111111111'); | ||
assert.equal(new BN('1000000000000000000000000000000000000000', 2) | ||
.ior(new BN('1', 2)) | ||
.toString(2), '1000000000000000000000000000000000000001'); | ||
assert.equal(new BN('1', 2) | ||
.ior(new BN('1000000000000000000000000000000000000000', 2)) | ||
.toString(2), '1000000000000000000000000000000000000001'); | ||
}); | ||
it('should xor numbers', function () { | ||
assert.equal(new BN('11001100110011001100110011001100', 2) | ||
.xor(new BN('1100110011001100110011001100110', 2)) | ||
.toString(2), '10101010101010101010101010101010'); | ||
}); | ||
it('should ixor numbers', function () { | ||
assert.equal(new BN('11001100110011001100110011001100', 2) | ||
.ixor(new BN('1100110011001100110011001100110', 2)) | ||
.toString(2), '10101010101010101010101010101010'); | ||
assert.equal(new BN('11001100110011001100110011001100', 2) | ||
.ixor(new BN('1', 2)) | ||
.toString(2), '11001100110011001100110011001101'); | ||
assert.equal(new BN('1', 2) | ||
.ixor(new BN('11001100110011001100110011001100', 2)) | ||
.toString(2), '11001100110011001100110011001101'); | ||
}); | ||
it('should allow single bits to be set', function () { | ||
assert.equal(new BN(0).setn(2, true).toString(2), '100'); | ||
assert.equal(new BN(0).setn(27, true).toString(2), | ||
'1000000000000000000000000000'); | ||
assert.equal(new BN('1000000000000000000000000001', 2).setn(27, false) | ||
.toString(2), '1'); | ||
assert.equal(new BN('101', 2).setn(2, false).toString(2), '1'); | ||
}); | ||
}); |
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
95440
2639
10