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.
Files changed (2) hide show
  1. package/lib/bn.js +11 -6
  2. 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
- this.length = num === 0 ? 1 : this.length;
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.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
2472
+ var mod = dm.mod.abs();
2470
2473
 
2471
- var half = num.ushrn(1);
2472
- var r2 = num.andln(1);
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
- return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bn.js",
3
- "version": "4.12.4",
3
+ "version": "4.12.5",
4
4
  "description": "Big number implementation in pure javascript",
5
5
  "main": "lib/bn.js",
6
6
  "scripts": {