Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bn.js

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bn.js - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

102

lib/bn.js

@@ -197,3 +197,3 @@ function assert(val, msg) {

while (c.cmpn(0) !== 0) {
var tmp = c._div(div10);
var tmp = c.divmod(div10, 'all');
var r = tmp.mod;

@@ -278,3 +278,3 @@ c = tmp.div;

// Add `num` to `this` in-place
BN.prototype.iadd = function iadd(num, base) {
BN.prototype.iadd = function iadd(num) {
// negative + positive

@@ -332,3 +332,3 @@ if (this.sign && !num.sign) {

// Add `num` to `this`
BN.prototype.add = function add(num, base) {
BN.prototype.add = function add(num) {
if (num.sign && !this.sign)

@@ -346,3 +346,3 @@ return this.sub(num.neg());

// Subtract `num` from `this` in-place
BN.prototype.isub = function isub(num, base) {
BN.prototype.isub = function isub(num) {
// this - (-num) = this + num

@@ -418,8 +418,8 @@ if (num.sign) {

// Subtract `num` from `this`
BN.prototype.sub = function sub(num, base) {
return this.clone().isub(num, base);
BN.prototype.sub = function sub(num) {
return this.clone().isub(num);
};
// Multiply `this` by `num`
BN.prototype.mul = function mul(num, base) {
BN.prototype.mul = function mul(num) {
if (this === num)

@@ -656,3 +656,3 @@ return this.sqr();

BN.prototype._shiftDiv = function _shiftDiv(num) {
BN.prototype._shiftDiv = function _shiftDiv(num, mode) {
// Find maximum Q, Q * num <= this

@@ -668,13 +668,26 @@ var shift = Math.max(0, this.bitLength() - num.bitLength());

var c = this.clone();
var r = new BN(0);
while (c.cmp(num) >= 0) {
assert(shift >= 0);
if (c.cmp(max) >= 0) {
c.isub(max);
r.bincn(shift);
if (mode === 'mod') {
var r = null;
while (c.cmp(num) >= 0) {
assert(shift >= 0);
if (c.cmp(max) >= 0)
c.isub(max);
var delta = Math.max(1, maxLen - c.bitLength());
max.ishrn(delta, shift);
maxLen -= delta;
shift -= delta;
}
var delta = Math.max(1, maxLen - c.bitLength());
max.ishrn(delta, shift);
maxLen -= delta;
shift -= delta;
} else {
var r = new BN(0);
while (c.cmp(num) >= 0) {
assert(shift >= 0);
if (c.cmp(max) >= 0) {
c.isub(max);
r.bincn(shift);
}
var delta = Math.max(1, maxLen - c.bitLength());
max.ishrn(delta, shift);
maxLen -= delta;
shift -= delta;
}
}

@@ -685,16 +698,25 @@

BN.prototype._div = function _div(num, base) {
BN.prototype.divmod = function divmod(num, mode) {
assert(num.cmpn(0) !== 0);
if (this.sign && !num.sign) {
var res = this.neg()._div(num);
var res = this.neg().divmod(num, mode);
var div;
var mod;
if (mode !== 'mod')
div = res.div.neg();
if (mode !== 'div')
mod = res.mod.cmpn(0) === 0 ? res.mod : num.sub(res.mod);
return {
div: res.div.neg(),
mod: res.mod.cmpn(0) === 0 ? res.mod : num.sub(res.mod)
div: div,
mod: mod
};
} else if (!this.sign && num.sign) {
var res = this._div(num.neg());
return { div: res.div.neg(), mod: res.mod };
var res = this.divmod(num.neg(), mode);
var div;
if (mode !== 'mod')
div = res.div.neg();
return { div: div, mod: res.mod };
} else if (this.sign && num.sign) {
return this.neg()._div(num.neg());
return this.neg().divmod(num.neg(), mode);
}

@@ -710,13 +732,13 @@

else
return this._shiftDiv(num);
return this._shiftDiv(num, mode);
};
// Find `this` / `num`
BN.prototype.div = function div(num, base) {
return this._div(num, base).div;
BN.prototype.div = function div(num) {
return this.divmod(num, 'div').div;
};
// Find `this` % `num`
BN.prototype.mod = function mod(num, base) {
return this._div(num, base).mod;
BN.prototype.mod = function mod(num) {
return this.divmod(num, 'mod').mod;
};

@@ -769,3 +791,3 @@

// Invert number in the field F(num)
BN.prototype.invm = function invm(num, base) {
BN.prototype.invm = function invm(num) {
return this._egcd(new BN(1), num);

@@ -847,3 +869,3 @@ };

// -1 - if `this` < `num`
BN.prototype.cmp = function cmp(num, base) {
BN.prototype.cmp = function cmp(num) {
if (this.sign && !num.sign)

@@ -908,3 +930,3 @@ return -1;

BN.prototype.montAdd = function montAdd(num, base) {
BN.prototype.montAdd = function montAdd(num) {
this._montVerify(num);

@@ -920,3 +942,3 @@

BN.prototype.montIAdd = function montIAdd(num, base) {
BN.prototype.montIAdd = function montIAdd(num) {
this._montVerify(num);

@@ -932,3 +954,3 @@

BN.prototype.montSub = function montSub(num, base) {
BN.prototype.montSub = function montSub(num) {
this._montVerify(num);

@@ -945,3 +967,3 @@

BN.prototype.montISub = function montISub(num, base) {
BN.prototype.montISub = function montISub(num) {
this._montVerify(num);

@@ -968,3 +990,3 @@

BN.prototype.montMul = function montMul(num, base) {
BN.prototype.montMul = function montMul(num) {
this._montVerify(num);

@@ -1035,3 +1057,3 @@

BN.prototype.montPow = function montPow(num, base) {
BN.prototype.montPow = function montPow(num) {
assert(this.mont && !num.mont, 'montPow(montNum, normalNum)');

@@ -1064,4 +1086,4 @@

BN.mont = function mont(num, base) {
return new Mont(num, base);
BN.mont = function mont(num) {
return new Mont(num);
};

@@ -1068,0 +1090,0 @@

{
"name": "bn.js",
"version": "0.4.0",
"version": "0.4.1",
"description": "Big number implementation in pure javascript",

@@ -5,0 +5,0 @@ "main": "lib/bn.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc