bn.js 5.2.4 → 5.2.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
|
@@ -2014,7 +2014,10 @@
|
|
|
2014
2014
|
this.words[i] = carry;
|
|
2015
2015
|
this.length++;
|
|
2016
2016
|
}
|
|
2017
|
-
|
|
2017
|
+
if (num === 0) {
|
|
2018
|
+
this.length = 1;
|
|
2019
|
+
this._normSign();
|
|
2020
|
+
}
|
|
2018
2021
|
|
|
2019
2022
|
return isNegNum ? this.ineg() : this;
|
|
2020
2023
|
};
|
|
@@ -2553,17 +2556,19 @@
|
|
|
2553
2556
|
// Fast case - exact division
|
|
2554
2557
|
if (dm.mod.isZero()) return dm.div;
|
|
2555
2558
|
|
|
2556
|
-
var mod = dm.
|
|
2559
|
+
var mod = dm.mod.abs();
|
|
2557
2560
|
|
|
2558
|
-
var half = num.
|
|
2559
|
-
var r2 = num.
|
|
2561
|
+
var half = num.abs().iushrn(1);
|
|
2562
|
+
var r2 = num.words[0] & 1;
|
|
2560
2563
|
var cmp = mod.cmp(half);
|
|
2561
2564
|
|
|
2562
2565
|
// Round down
|
|
2563
2566
|
if (cmp < 0 || (r2 === 1 && cmp === 0)) return dm.div;
|
|
2564
2567
|
|
|
2565
|
-
// Round up
|
|
2566
|
-
|
|
2568
|
+
// Round up, away from zero
|
|
2569
|
+
var up = new BN(1);
|
|
2570
|
+
up.negative = this.negative ^ num.negative;
|
|
2571
|
+
return dm.div.iadd(up);
|
|
2567
2572
|
};
|
|
2568
2573
|
|
|
2569
2574
|
BN.prototype.modrn = function modrn (num) {
|