bn.js 4.12.4 → 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 +11 -6
- package/package.json +1 -1
package/lib/bn.js
CHANGED
|
@@ -1927,7 +1927,10 @@
|
|
|
1927
1927
|
this.words[i] = carry;
|
|
1928
1928
|
this.length++;
|
|
1929
1929
|
}
|
|
1930
|
-
|
|
1930
|
+
if (num === 0) {
|
|
1931
|
+
this.length = 1;
|
|
1932
|
+
this._normSign();
|
|
1933
|
+
}
|
|
1931
1934
|
|
|
1932
1935
|
return this;
|
|
1933
1936
|
};
|
|
@@ -2466,17 +2469,19 @@
|
|
|
2466
2469
|
// Fast case - exact division
|
|
2467
2470
|
if (dm.mod.isZero()) return dm.div;
|
|
2468
2471
|
|
|
2469
|
-
var mod = dm.
|
|
2472
|
+
var mod = dm.mod.abs();
|
|
2470
2473
|
|
|
2471
|
-
var half = num.
|
|
2472
|
-
var r2 = num.
|
|
2474
|
+
var half = num.abs().iushrn(1);
|
|
2475
|
+
var r2 = num.words[0] & 1;
|
|
2473
2476
|
var cmp = mod.cmp(half);
|
|
2474
2477
|
|
|
2475
2478
|
// Round down
|
|
2476
2479
|
if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
|
|
2477
2480
|
|
|
2478
|
-
// Round up
|
|
2479
|
-
|
|
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);
|
|
2480
2485
|
};
|
|
2481
2486
|
|
|
2482
2487
|
BN.prototype.modn = function modn (num) {
|