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.
Files changed (2) hide show
  1. package/lib/bn.js +11 -6
  2. 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
- this.length = num === 0 ? 1 : this.length;
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.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
2559
+ var mod = dm.mod.abs();
2557
2560
 
2558
- var half = num.ushrn(1);
2559
- var r2 = num.andln(1);
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
- return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bn.js",
3
- "version": "5.2.4",
3
+ "version": "5.2.5",
4
4
  "description": "Big number implementation in pure javascript",
5
5
  "keywords": [
6
6
  "BN",