Comparing version 1.2.1 to 1.2.2
17
1.js
@@ -1,8 +0,11 @@ | ||
var BN = require('./'); | ||
var bn = require('./'); | ||
var a = new BN("6582018229284824168619876730229320890292528855852623664389292032"); | ||
var b = new BN("730750818665451459101842416358132502628711530497"); | ||
console.log(b.words); | ||
var q = a.div(b); | ||
var m = a.mod(b); | ||
console.log(q, m); | ||
var a1 = new bn('123456789abcdef0123456789abcdef0123456789abcdef0123', 'hex'); | ||
var as1 = a1.mul(a1).iaddn(0xdeadbeef & 0x3ffffff); | ||
console.time('div'); | ||
for (var i = 0; i < 2000000; i++) | ||
var q = as1.div(a1); | ||
console.timeEnd('div'); | ||
console.log(q); |
@@ -858,3 +858,2 @@ // Utils | ||
var o = this.clone(); | ||
if (r !== 0) { | ||
@@ -1079,13 +1078,5 @@ var carry = 0; | ||
BN.prototype._ishlnadd = function _ishlnadd(num, shift) { | ||
assert(!num.sign); | ||
if (this.sign) { | ||
this.sign = false; | ||
this._ishlnsub(num, shift); | ||
this.sign = !this.sign; | ||
return this; | ||
} | ||
BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { | ||
// Bigger storage is needed | ||
var len = num.length + shift + 1; | ||
var len = num.length + shift; | ||
if (this.words.length < len) { | ||
@@ -1107,46 +1098,8 @@ var t = new Array(len); | ||
for (var i = 0; i < num.length; i++) { | ||
var w = this.words[i + shift] + num.words[i] + carry; | ||
carry = w >> 26; | ||
this.words[i + shift] = w & 0x3ffffff; | ||
} | ||
for (; i < this.length - shift; i++) { | ||
var w = this.words[i + shift] + carry; | ||
carry = w >> 26; | ||
var right = num.words[i] * mul; | ||
w -= right & 0x3ffffff; | ||
carry = (w >> 26) - ((right / 0x4000000) | 0); | ||
this.words[i + shift] = w & 0x3ffffff; | ||
} | ||
return this.strip(); | ||
}; | ||
BN.prototype._ishlnsub = function _ishlnsub(num, shift) { | ||
assert(!num.sign); | ||
if (this.sign) { | ||
this.sign = false; | ||
this._ishlnadd(num, shift); | ||
this.sign = !this.sign; | ||
return this; | ||
} | ||
// Bigger storage is needed | ||
var len = num.length + shift; | ||
if (this.words.length < len) { | ||
var t = new Array(len); | ||
for (var i = 0; i < this.length; i++) | ||
t[i] = this.words[i]; | ||
this.words = t; | ||
} else { | ||
i = this.length; | ||
} | ||
// Zeroify rest | ||
this.length = Math.max(this.length, len); | ||
for (; i < this.length; i++) | ||
this.words[i] = 0; | ||
var carry = 0; | ||
for (var i = 0; i < num.length; i++) { | ||
var w = this.words[i + shift] - num.words[i] + carry; | ||
carry = w >> 26; | ||
this.words[i + shift] = w & 0x3ffffff; | ||
} | ||
for (; i < this.length - shift; i++) { | ||
@@ -1202,3 +1155,3 @@ var w = this.words[i + shift] + carry; | ||
var diff = a.clone()._ishlnsub(b, m); | ||
var diff = a.clone()._ishlnsubmul(b, 1, m); | ||
if (!diff.sign) { | ||
@@ -1210,5 +1163,2 @@ a = diff; | ||
var st = new BN(null); | ||
st.words = new Array(b.length + 1); | ||
st.length = 0; | ||
for (var j = m - 1; j >= 0; j--) { | ||
@@ -1221,9 +1171,8 @@ var qj = a.words[b.length + j] * 0x4000000 + a.words[b.length + j - 1]; | ||
for (var i = 0; i < b.length; i++) | ||
st.words[i] = b.words[i]; | ||
st.length = b.length; | ||
a._ishlnsub(st.imuln(qj), j); | ||
a._ishlnsubmul(b, qj, j); | ||
while (a.sign) { | ||
qj--; | ||
a._ishlnadd(b, j); | ||
a.sign = false; | ||
a._ishlnsubmul(b, 1, j); | ||
a.sign = !a.sign; | ||
} | ||
@@ -1238,3 +1187,3 @@ if (q) | ||
// Denormalize | ||
if (shift !== 0) | ||
if (mode !== 'div' && shift !== 0) | ||
a.ishrn(shift); | ||
@@ -1241,0 +1190,0 @@ return { div: q ? q : null, mod: a }; |
{ | ||
"name": "bn.js", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Big number implementation in pure javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/bn.js", |
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
84780
2519