bn.js 4.12.3 → 4.12.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bn.js +17 -6
- package/package.json +1 -1
package/lib/bn.js
CHANGED
|
@@ -828,6 +828,12 @@
|
|
|
828
828
|
// Handle the residue
|
|
829
829
|
if (bitsLeft > 0) {
|
|
830
830
|
this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
|
|
831
|
+
i++;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// Clear words above the requested width so the result stays below 2 ** width
|
|
835
|
+
for (; i < this.length; i++) {
|
|
836
|
+
this.words[i] = 0;
|
|
831
837
|
}
|
|
832
838
|
|
|
833
839
|
// And remove leading zeroes
|
|
@@ -1921,7 +1927,10 @@
|
|
|
1921
1927
|
this.words[i] = carry;
|
|
1922
1928
|
this.length++;
|
|
1923
1929
|
}
|
|
1924
|
-
|
|
1930
|
+
if (num === 0) {
|
|
1931
|
+
this.length = 1;
|
|
1932
|
+
this._normSign();
|
|
1933
|
+
}
|
|
1925
1934
|
|
|
1926
1935
|
return this;
|
|
1927
1936
|
};
|
|
@@ -2460,17 +2469,19 @@
|
|
|
2460
2469
|
// Fast case - exact division
|
|
2461
2470
|
if (dm.mod.isZero()) return dm.div;
|
|
2462
2471
|
|
|
2463
|
-
var mod = dm.
|
|
2472
|
+
var mod = dm.mod.abs();
|
|
2464
2473
|
|
|
2465
|
-
var half = num.
|
|
2466
|
-
var r2 = num.
|
|
2474
|
+
var half = num.abs().iushrn(1);
|
|
2475
|
+
var r2 = num.words[0] & 1;
|
|
2467
2476
|
var cmp = mod.cmp(half);
|
|
2468
2477
|
|
|
2469
2478
|
// Round down
|
|
2470
2479
|
if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
|
2471
2480
|
|
|
2472
|
-
// Round up
|
|
2473
|
-
|
|
2481
|
+
// Round up, away from zero
|
|
2482
|
+
var up = new BN(1);
|
|
2483
|
+
up.negative = this.negative ^ num.negative;
|
|
2484
|
+
return dm.div.iadd(up);
|
|
2474
2485
|
};
|
|
2475
2486
|
|
|
2476
2487
|
BN.prototype.modn = function modn (num) {
|