Socket
Socket
Sign inDemoInstall

big-integer

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

big-integer - npm Package Compare versions

Comparing version 1.2.14 to 1.3.14

136

BigInteger.js

@@ -14,2 +14,12 @@ "use strict";

function trim(value) {
var trimmedValue = [], highestDigit = 0;
for (var i = value.length - 1; i >= 0; i--) {
if (i > highestDigit && value[i] === 0) continue;
highestDigit = i;
trimmedValue[i] = value[i];
}
return trimmedValue;
}
BigInteger.prototype.negate = function () {

@@ -37,3 +47,3 @@ return new BigInteger(this.value, !this.sign);

}
return new BigInteger(result, this.sign);
return new BigInteger(trim(result), this.sign);
};

@@ -59,3 +69,3 @@ BigInteger.prototype.plus = function (n) {

}
return new BigInteger(result, sign.positive);
return new BigInteger(trim(result), sign.positive);
};

@@ -105,3 +115,3 @@ BigInteger.prototype.minus = function (n) {

}
return new BigInteger(result, sign);
return new BigInteger(trim(result), sign);
};

@@ -129,4 +139,4 @@ BigInteger.prototype.times = function (n) {

return {
quotient: new BigInteger(result, sign),
remainder: new BigInteger(remainder, this.sign)
quotient: new BigInteger(trim(result), sign),
remainder: new BigInteger(trim(remainder), this.sign)
};

@@ -149,10 +159,10 @@ };

var a = this, b = n, r = ONE;
if (b.equals(0)) return r;
if (a.equals(0) || b.lesser(0)) return ZERO;
if (b.equals(ZERO)) return r;
if (a.equals(ZERO) || b.lesser(ZERO)) return ZERO;
while (true) {
if (b.mod(2).equals(1)) {
if (b.isOdd()) {
r = r.times(a);
}
b = b.over(2);
if (b.equals(0)) break;
b = b.divide(2);
if (b.equals(ZERO)) break;
a = a.times(a);

@@ -162,2 +172,44 @@ }

};
BigInteger.prototype.modPow = function (exp, mod) {
exp = parseInput(exp);
mod = parseInput(mod);
if (mod.equals(ZERO)) throw new Error("Cannot take modPow with modulus 0");
var r = ONE,
base = this.mod(mod);
if (base.equals(ZERO)) return ZERO;
while (exp.greater(0)) {
if (exp.isOdd()) r = r.multiply(base).mod(mod);
exp = exp.divide(2);
base = base.square().mod(mod);
}
return r;
};
BigInteger.prototype.square = function () {
return this.multiply(this);
};
function gcd(a, b) {
a = parseInput(a).abs();
b = parseInput(b).abs();
if (a.equals(b)) return a;
if (a.equals(ZERO)) return b;
if (b.equals(ZERO)) return a;
if (a.isEven()) {
if (b.isOdd()) {
return gcd(a.divide(2), b);
}
return gcd(a.divide(2), b.divide(2)).multiply(2);
}
if (b.isEven()) {
return gcd(a, b.divide(2));
}
if (a.greater(b)) {
return gcd(a.subtract(b).divide(2), b);
}
return gcd(b.subtract(a).divide(2), a);
}
function lcm(a, b) {
a = parseInput(a).abs();
b = parseInput(b).abs();
return a.multiply(b).divide(gcd(a, b));
}
BigInteger.prototype.next = function () {

@@ -207,2 +259,12 @@ return this.add(1);

};
function max (a, b) {
a = parseInput(a);
b = parseInput(b);
return a.greater(b) ? a : b;
}
function min (a, b) {
a = parseInput(a);
b = parseInput(b);
return a.lesser(b) ? a : b;
}
BigInteger.prototype.isPositive = function () {

@@ -220,2 +282,45 @@ return this.sign === sign.positive;

};
BigInteger.prototype.isUnit = function () {
return this.value.length === 1 && this.value[0] === 1;
};
BigInteger.prototype.isDivisibleBy = function (n) {
return this.mod(n).equals(ZERO);
};
BigInteger.prototype.isPrime = function () {
var n = this.abs(),
nPrev = n.prev();
if (n.isUnit()) return false;
if (n.equals(2) || n.equals(3) || n.equals(5)) return true;
if (n.isEven() || n.isDivisibleBy(3) || n.isDivisibleBy(5)) return false;
if (n.lesser(25)) return true;
var a = [2, 3, 5, 7, 11, 13, 17, 19],
b = nPrev,
d, t, i, x;
while (b.isEven()) b = b.divide(2);
for (i = 0; i < a.length; i++) {
x = bigInt(a[i]).modPow(b, n);
if (x.equals(ONE) || x.equals(nPrev)) continue;
for (t = true, d = b; t && d.lesser(nPrev); d = d.multiply(2)) {
x = x.square().mod(n);
if (x.equals(nPrev)) t = false;
}
if (t) return false;
}
return true;
};
function randBetween (a, b) {
a = parseInput(a);
b = parseInput(b);
var low = min(a, b), high = max(a, b);
var range = high.subtract(low);
var length = range.value.length - 1;
var result = [], restricted = true;
for (var i = length; i >= 0; i--) {
var top = restricted ? range.value[i] : base;
var digit = Math.floor(Math.random() * top);
result.unshift(digit);
if (digit < top) restricted = false;
}
return low.add(new BigInteger(result, false));
}
BigInteger.prototype.toString = function (b) {

@@ -273,3 +378,3 @@ var first = this;

function parseInput(text) {
if (typeof text === "object") return text;
if (text instanceof BigInteger) return text;
if (Math.abs(+text) < base && +text === (+text | 0)) {

@@ -286,3 +391,3 @@ var value = +text;

var text = text.split(/e/i);
if (text.length > 2) throw new Error("Invalid integer");
if (text.length > 2) throw new Error("Invalid integer: " + text.join("e"));
if (text[1]) {

@@ -301,3 +406,3 @@ var exp = text[1];

var isValid = /^([0-9][0-9]*)$/.test(text);
if (!isValid) throw new Error("Invalid integer");
if (!isValid) throw new Error("Invalid integer: " + text);
while (text.length) {

@@ -350,2 +455,7 @@ var divider = text.length > logBase ? text.length - logBase : 0;

fnReturn.minusOne = MINUS_ONE;
fnReturn.randBetween = randBetween;
fnReturn.min = min;
fnReturn.max = max;
fnReturn.gcd = gcd;
fnReturn.lcm = lcm;
return fnReturn;

@@ -352,0 +462,0 @@ })();

2

BigInteger.min.js

@@ -1,1 +0,1 @@

"use strict";var bigInt=function(){function r(e,t){this.value=e,this.sign=t}function a(i){if(typeof i=="object")return i;if(Math.abs(+i)<e&&+i===(+i|0)){var s=+i;return new r([Math.abs(s)],s<0||1/s===-Infinity)}i+="";var o=n.positive,s=[];i[0]==="-"&&(o=n.negative,i=i.slice(1));var i=i.split(/e/i);if(i.length>2)throw new Error("Invalid integer");if(i[1]){var u=i[1];u[0]==="+"&&(u=u.slice(1)),u=a(u);if(u.lesser(0))throw new Error("Cannot include negative exponent part for integers");while(u.notEquals(0))i[0]+="0",u=u.prev()}i=i[0],i==="-0"&&(i="0");var f=/^([0-9][0-9]*)$/.test(i);if(!f)throw new Error("Invalid integer");while(i.length){var l=i.length>t?i.length-t:0;s.push(+i.slice(l)),i=i.slice(0,l)}return new r(s,o)}var e=1e7,t=7,n={positive:!1,negative:!0};r.prototype.negate=function(){return new r(this.value,!this.sign)},r.prototype.abs=function(){return new r(this.value,n.positive)},r.prototype.add=function(t){t=a(t);if(this.sign!==t.sign)return this.sign===n.positive?this.abs().subtract(t.abs()):t.abs().subtract(this.abs());var i=this.value,s=t.value,o=[],u=0,f=Math.max(i.length,s.length);for(var l=0;l<f||u>0;l++){var c=(i[l]||0)+(s[l]||0)+u;u=c>=e?1:0,c-=u*e,o.push(c)}return new r(o,this.sign)},r.prototype.plus=function(e){return this.add(e)},r.prototype.subtract=function(t){t=a(t);if(this.sign!==t.sign)return this.add(t.negate());if(this.sign===n.negative)return t.negate().subtract(this.negate());if(this.compare(t)<0)return t.subtract(this).negate();var i=this.value,s=t.value,o=[],u=0,f=Math.max(i.length,s.length);for(var l=0;l<f;l++){var c=i[l]||0,h=s[l]||0,p=c-u;u=p<h?1:0;var d=u*e+p-h;o.push(d)}return new r(o,n.positive)},r.prototype.minus=function(e){return this.subtract(e)},r.prototype.multiply=function(t){t=a(t);var n=this.sign!==t.sign,i=this.value,s=t.value,o=Math.max(i.length,s.length),u=[];for(var f=0;f<o;f++){u[f]=[];var l=f;while(l--)u[f].push(0)}var c=0;for(var f=0;f<i.length;f++){var h=i[f];for(var l=0;l<s.length||c>0;l++){var p=s[l],d=p?h*p+c:c;c=d>e?Math.floor(d/e):0,d-=c*e,u[f].push(d)}}var v=-1;for(var f=0;f<u.length;f++){var m=u[f].length;m>v&&(v=m)}var g=[],c=0;for(var f=0;f<v||c>0;f++){var y=c;for(var l=0;l<u.length;l++)y+=u[l][f]||0;c=y>e?Math.floor(y/e):0,y-=c*e,g.push(y)}return new r(g,n)},r.prototype.times=function(e){return this.multiply(e)},r.prototype.divmod=function(e){e=a(e);var t=this.sign!==e.sign;if(this.equals(0))return{quotient:new r([0],t.positive),remainder:new r([0],t.positive)};if(e.equals(0))throw new Error("Cannot divide by zero");var n=this.value,s=e.value,o=[],u=[];for(var f=n.length-1;f>=0;f--){var l=[n[f]].concat(u),c=i(s,l);o.push(c.result),u=c.remainder}return o.reverse(),{quotient:new r(o,t),remainder:new r(u,this.sign)}},r.prototype.divide=function(e){return this.divmod(e).quotient},r.prototype.over=function(e){return this.divide(e)},r.prototype.mod=function(e){return this.divmod(e).remainder},r.prototype.remainder=function(e){return this.mod(e)},r.prototype.pow=function(e){e=a(e);var t=this,n=e,r=o;if(n.equals(0))return r;if(t.equals(0)||n.lesser(0))return s;for(;;){n.mod(2).equals(1)&&(r=r.times(t)),n=n.over(2);if(n.equals(0))break;t=t.times(t)}return r},r.prototype.next=function(){return this.add(1)},r.prototype.prev=function(){return this.subtract(1)},r.prototype.compare=function(e){var t=this,r=a(e);if(t.value.length===1&&r.value.length===1&&t.value[0]===0&&r.value[0]===0)return 0;if(r.sign!==t.sign)return t.sign===n.positive?1:-1;var i=t.sign===n.positive?1:-1,s=t.value,o=r.value,u=Math.max(s.length,o.length)-1;for(var f=u;f>=0;f--){var l=s[f]||0,c=o[f]||0;if(l>c)return 1*i;if(c>l)return-1*i}return 0},r.prototype.compareTo=function(e){return this.compare(e)},r.prototype.compareAbs=function(e){return this.abs().compare(e.abs())},r.prototype.equals=function(e){return this.compare(e)===0},r.prototype.notEquals=function(e){return!this.equals(e)},r.prototype.lesser=function(e){return this.compare(e)<0},r.prototype.greater=function(e){return this.compare(e)>0},r.prototype.greaterOrEquals=function(e){return this.compare(e)>=0},r.prototype.lesserOrEquals=function(e){return this.compare(e)<=0},r.prototype.isPositive=function(){return this.sign===n.positive},r.prototype.isNegative=function(){return this.sign===n.negative},r.prototype.isEven=function(){return this.value[0]%2===0},r.prototype.isOdd=function(){return this.value[0]%2===1},r.prototype.toString=function(r){var i=this,s="",o=i.value.length;while(o--)i.value[o].toString().length===8?s+=i.value[o]:s+=(e.toString()+i.value[o]).slice(-t);while(s[0]==="0")s=s.slice(1);s.length||(s="0");if(s==="0")return s;var u=i.sign===n.positive?"":"-";return u+s},r.prototype.toJSNumber=function(){return+this.toString()},r.prototype.valueOf=function(){return this.toJSNumber()};var i=function(e,t){var e=new r(e,n.positive),t=new r(t,n.positive);if(e.equals(0))throw new Error("Cannot divide by 0");var i=0;do{var s=1,o=e,u=o.times(10);while(u.lesser(t))o=u,s*=10,u=u.times(10);while(o.lesserOrEquals(t))t=t.minus(o),i+=s}while(e.lesserOrEquals(t));return{remainder:t.value,result:i}},s=new r([0],n.positive),o=new r([1],n.positive),u=new r([1],n.negative),f=function(e,t){function u(e){var t=e[i].toLowerCase();if(i===0&&e[i]==="-"){o=!0;return}if(/[0-9]/.test(t))r.push(a(t));else if(/[a-z]/.test(t))r.push(a(t.charCodeAt(0)-87));else{if(t!=="<")throw new Error(t+" is not a valid character");var n=i;do i++;while(e[i]!==">");r.push(a(e.slice(n+1,i)))}}t=a(t);var n=s,r=[],i,o=!1;for(i=0;i<e.length;i++)u(e);r.reverse();for(i=0;i<r.length;i++)n=n.add(r[i].times(t.pow(i)));return o?n.negate():n},l=function(e,t){return typeof e=="undefined"?s:typeof t!="undefined"?f(e,t):a(e)};return l.zero=s,l.one=o,l.minusOne=u,l}();typeof module!="undefined"&&(module.exports=bigInt);
"use strict";var bigInt=function(){function r(e,t){this.value=e,this.sign=t}function i(e){var t=[],n=0;for(var r=e.length-1;r>=0;r--){if(r>n&&e[r]===0)continue;n=r,t[r]=e[r]}return t}function s(e,t){return e=d(e).abs(),t=d(t).abs(),e.equals(t)?e:e.equals(c)?t:t.equals(c)?e:e.isEven()?t.isOdd()?s(e.divide(2),t):s(e.divide(2),t.divide(2)).multiply(2):t.isEven()?s(e,t.divide(2)):e.greater(t)?s(e.subtract(t).divide(2),t):s(t.subtract(e).divide(2),e)}function o(e,t){return e=d(e).abs(),t=d(t).abs(),e.multiply(t).divide(s(e,t))}function u(e,t){return e=d(e),t=d(t),e.greater(t)?e:t}function a(e,t){return e=d(e),t=d(t),e.lesser(t)?e:t}function f(t,n){t=d(t),n=d(n);var i=a(t,n),s=u(t,n),o=s.subtract(i),f=o.value.length-1,l=[],c=!0;for(var h=f;h>=0;h--){var p=c?o.value[h]:e,v=Math.floor(Math.random()*p);l.unshift(v),v<p&&(c=!1)}return i.add(new r(l,!1))}function d(i){if(i instanceof r)return i;if(Math.abs(+i)<e&&+i===(+i|0)){var s=+i;return new r([Math.abs(s)],s<0||1/s===-Infinity)}i+="";var o=n.positive,s=[];i[0]==="-"&&(o=n.negative,i=i.slice(1));var i=i.split(/e/i);if(i.length>2)throw new Error("Invalid integer: "+i.join("e"));if(i[1]){var u=i[1];u[0]==="+"&&(u=u.slice(1)),u=d(u);if(u.lesser(0))throw new Error("Cannot include negative exponent part for integers");while(u.notEquals(0))i[0]+="0",u=u.prev()}i=i[0],i==="-0"&&(i="0");var a=/^([0-9][0-9]*)$/.test(i);if(!a)throw new Error("Invalid integer: "+i);while(i.length){var f=i.length>t?i.length-t:0;s.push(+i.slice(f)),i=i.slice(0,f)}return new r(s,o)}var e=1e7,t=7,n={positive:!1,negative:!0};r.prototype.negate=function(){return new r(this.value,!this.sign)},r.prototype.abs=function(){return new r(this.value,n.positive)},r.prototype.add=function(t){t=d(t);if(this.sign!==t.sign)return this.sign===n.positive?this.abs().subtract(t.abs()):t.abs().subtract(this.abs());var s=this.value,o=t.value,u=[],a=0,f=Math.max(s.length,o.length);for(var l=0;l<f||a>0;l++){var c=(s[l]||0)+(o[l]||0)+a;a=c>=e?1:0,c-=a*e,u.push(c)}return new r(i(u),this.sign)},r.prototype.plus=function(e){return this.add(e)},r.prototype.subtract=function(t){t=d(t);if(this.sign!==t.sign)return this.add(t.negate());if(this.sign===n.negative)return t.negate().subtract(this.negate());if(this.compare(t)<0)return t.subtract(this).negate();var s=this.value,o=t.value,u=[],a=0,f=Math.max(s.length,o.length);for(var l=0;l<f;l++){var c=s[l]||0,h=o[l]||0,p=c-a;a=p<h?1:0;var v=a*e+p-h;u.push(v)}return new r(i(u),n.positive)},r.prototype.minus=function(e){return this.subtract(e)},r.prototype.multiply=function(t){t=d(t);var n=this.sign!==t.sign,s=this.value,o=t.value,u=Math.max(s.length,o.length),a=[];for(var f=0;f<u;f++){a[f]=[];var l=f;while(l--)a[f].push(0)}var c=0;for(var f=0;f<s.length;f++){var h=s[f];for(var l=0;l<o.length||c>0;l++){var p=o[l],v=p?h*p+c:c;c=v>e?Math.floor(v/e):0,v-=c*e,a[f].push(v)}}var m=-1;for(var f=0;f<a.length;f++){var g=a[f].length;g>m&&(m=g)}var y=[],c=0;for(var f=0;f<m||c>0;f++){var b=c;for(var l=0;l<a.length;l++)b+=a[l][f]||0;c=b>e?Math.floor(b/e):0,b-=c*e,y.push(b)}return new r(i(y),n)},r.prototype.times=function(e){return this.multiply(e)},r.prototype.divmod=function(e){e=d(e);var t=this.sign!==e.sign;if(this.equals(0))return{quotient:new r([0],t.positive),remainder:new r([0],t.positive)};if(e.equals(0))throw new Error("Cannot divide by zero");var n=this.value,s=e.value,o=[],u=[];for(var a=n.length-1;a>=0;a--){var f=[n[a]].concat(u),c=l(s,f);o.push(c.result),u=c.remainder}return o.reverse(),{quotient:new r(i(o),t),remainder:new r(i(u),this.sign)}},r.prototype.divide=function(e){return this.divmod(e).quotient},r.prototype.over=function(e){return this.divide(e)},r.prototype.mod=function(e){return this.divmod(e).remainder},r.prototype.remainder=function(e){return this.mod(e)},r.prototype.pow=function(e){e=d(e);var t=this,n=e,r=h;if(n.equals(c))return r;if(t.equals(c)||n.lesser(c))return c;for(;;){n.isOdd()&&(r=r.times(t)),n=n.divide(2);if(n.equals(c))break;t=t.times(t)}return r},r.prototype.modPow=function(e,t){e=d(e),t=d(t);if(t.equals(c))throw new Error("Cannot take modPow with modulus 0");var n=h,r=this.mod(t);if(r.equals(c))return c;while(e.greater(0))e.isOdd()&&(n=n.multiply(r).mod(t)),e=e.divide(2),r=r.square().mod(t);return n},r.prototype.square=function(){return this.multiply(this)},r.prototype.next=function(){return this.add(1)},r.prototype.prev=function(){return this.subtract(1)},r.prototype.compare=function(e){var t=this,r=d(e);if(t.value.length===1&&r.value.length===1&&t.value[0]===0&&r.value[0]===0)return 0;if(r.sign!==t.sign)return t.sign===n.positive?1:-1;var i=t.sign===n.positive?1:-1,s=t.value,o=r.value,u=Math.max(s.length,o.length)-1;for(var a=u;a>=0;a--){var f=s[a]||0,l=o[a]||0;if(f>l)return 1*i;if(l>f)return-1*i}return 0},r.prototype.compareTo=function(e){return this.compare(e)},r.prototype.compareAbs=function(e){return this.abs().compare(e.abs())},r.prototype.equals=function(e){return this.compare(e)===0},r.prototype.notEquals=function(e){return!this.equals(e)},r.prototype.lesser=function(e){return this.compare(e)<0},r.prototype.greater=function(e){return this.compare(e)>0},r.prototype.greaterOrEquals=function(e){return this.compare(e)>=0},r.prototype.lesserOrEquals=function(e){return this.compare(e)<=0},r.prototype.isPositive=function(){return this.sign===n.positive},r.prototype.isNegative=function(){return this.sign===n.negative},r.prototype.isEven=function(){return this.value[0]%2===0},r.prototype.isOdd=function(){return this.value[0]%2===1},r.prototype.isUnit=function(){return this.value.length===1&&this.value[0]===1},r.prototype.isDivisibleBy=function(e){return this.mod(e).equals(c)},r.prototype.isPrime=function(){var e=this.abs(),t=e.prev();if(e.isUnit())return!1;if(e.equals(2)||e.equals(3)||e.equals(5))return!0;if(e.isEven()||e.isDivisibleBy(3)||e.isDivisibleBy(5))return!1;if(e.lesser(25))return!0;var n=[2,3,5,7,11,13,17,19],r=t,i,s,o,u;while(r.isEven())r=r.divide(2);for(o=0;o<n.length;o++){u=bigInt(n[o]).modPow(r,e);if(u.equals(h)||u.equals(t))continue;for(s=!0,i=r;s&&i.lesser(t);i=i.multiply(2))u=u.square().mod(e),u.equals(t)&&(s=!1);if(s)return!1}return!0},r.prototype.toString=function(r){var i=this,s="",o=i.value.length;while(o--)i.value[o].toString().length===8?s+=i.value[o]:s+=(e.toString()+i.value[o]).slice(-t);while(s[0]==="0")s=s.slice(1);s.length||(s="0");if(s==="0")return s;var u=i.sign===n.positive?"":"-";return u+s},r.prototype.toJSNumber=function(){return+this.toString()},r.prototype.valueOf=function(){return this.toJSNumber()};var l=function(e,t){var e=new r(e,n.positive),t=new r(t,n.positive);if(e.equals(0))throw new Error("Cannot divide by 0");var i=0;do{var s=1,o=e,u=o.times(10);while(u.lesser(t))o=u,s*=10,u=u.times(10);while(o.lesserOrEquals(t))t=t.minus(o),i+=s}while(e.lesserOrEquals(t));return{remainder:t.value,result:i}},c=new r([0],n.positive),h=new r([1],n.positive),p=new r([1],n.negative),v=function(e,t){function o(e){var t=e[i].toLowerCase();if(i===0&&e[i]==="-"){s=!0;return}if(/[0-9]/.test(t))r.push(d(t));else if(/[a-z]/.test(t))r.push(d(t.charCodeAt(0)-87));else{if(t!=="<")throw new Error(t+" is not a valid character");var n=i;do i++;while(e[i]!==">");r.push(d(e.slice(n+1,i)))}}t=d(t);var n=c,r=[],i,s=!1;for(i=0;i<e.length;i++)o(e);r.reverse();for(i=0;i<r.length;i++)n=n.add(r[i].times(t.pow(i)));return s?n.negate():n},m=function(e,t){return typeof e=="undefined"?c:typeof t!="undefined"?v(e,t):d(e)};return m.zero=c,m.one=h,m.minusOne=p,m.randBetween=f,m.min=a,m.max=u,m.gcd=s,m.lcm=o,m}();typeof module!="undefined"&&(module.exports=bigInt);

@@ -83,4 +83,4 @@ /// <reference path="BigInteger.js" />

"100 ^ 56 !== 0": bigInt(100).pow(56).toString() !== "0", //https://github.com/peterolson/BigInteger.js/issues/5
"Leading zeroes": bigInt("10000000").toString() == "10000000",
"Leading zeroes 2": bigInt("100001010000000").toString() == "100001010000000",
"Leading zeroes": bigInt("10000000").toString() === "10000000",
"Leading zeroes 2": bigInt("100001010000000").toString() === "100001010000000",
"10 Factorial": (function () {

@@ -134,5 +134,17 @@ var res = "3628800"; //http://www.wolframalpha.com/input/?i=10%21

"2e7 = 2E7": bigInt("2e7").equals("2E7"),
"-1 base 16 = -1 base 10": bigInt("-1", 16).equals("-1") // see pull request 15
"-1 base 16 = -1 base 10": bigInt("-1", 16).equals("-1"), // see pull request 15
"65536 squared is 4294967296": bigInt("65536").square().equals("4294967296"),
"1 is unit": bigInt.one.isUnit(),
"-1 is unit": bigInt.minusOne.isUnit(),
"5 is not a unit": !bigInt(5).isUnit(),
"4^13 (mod 497) = 445": bigInt(4).modPow(13, 497).equals(445),
"max(77,432) = 432": bigInt.max(77, 432).equals(432),
"min(32, 19) = 19": bigInt.min(32, 19).equals(19),
"lcm(21,6)=42": bigInt.lcm(21, 6).equals(42),
"gcd(42,56)=14": bigInt.gcd(42, 56).equals(14),
"999 is divisible by 333": bigInt(999).isDivisibleBy(333),
"7919 is prime": bigInt(7919).isPrime(),
"7917 is not prime": !bigInt(7917).isPrime()
});
return assertions.join("<br>");
})(bigInt);
{
"name": "big-integer",
"version": "1.2.14",
"version": "1.3.14",
"author": "Peter Olson <peter.e.c.olson+npm@gmail.com>",

@@ -5,0 +5,0 @@ "description": "An arbitrary length integer library for Javascript",

@@ -115,2 +115,8 @@ BigInteger.js

`gcd(a, b)`
---
Finds the greatest common denominator of `a` and `b`.
- `bigInt.gcd(42,56)` => `14`
`greater(number)`

@@ -132,4 +138,11 @@ ---

`isEven(number)`
`isDivisibleBy(number)`
---
Returns `true` if the first number is divisible by the second number, `false` otherwise.
- `bigInt(999).isDivisibleBy(333)` => `true`
- `bigInt(99).isDivisibleBy(5)` => `false`
`isEven()`
---
Returns `true` if the number is even, `false` otherwise.

@@ -140,3 +153,3 @@

`isNegative(number)`
`isNegative()`
---

@@ -149,3 +162,3 @@ Returns `true` if the number is negative, `false` otherwise.

`isOdd(number)`
`isOdd()`
---

@@ -157,4 +170,11 @@ Returns `true` if the number is odd, `false` otherwise.

`isPositive(number)`
`isPrime()`
---
Returns `true` if the number is prime, `false` otherwise.
- `bigInt(5).isPrime()` => `true`
- `bigInt(6).isPrime()` => `false`
`isPositive()`
---
Return `true` if the number is positive, `false` otherwise.

@@ -166,2 +186,16 @@ Returns `true` for `0` and `false` for `-0`.

`isUnit()`
---
Return `true` if the number is `1` or `-1`, `false` otherwise.
- `bigInt.one.isUnit()` => `true`
- `bigInt.minusOne.isUnit()` => `true`
- `bigInt(5).isUnit()` => `false`
`lcm(a,b)`
---
Finds the least common multiple of `a` and `b`.
- `bigInt.lcm(21, 6)` => `42`
`lesser(number)`

@@ -183,2 +217,14 @@ ---

`max(a,b)`
---
Returns the largest of `a` and `b`.
- `bigInt.max(77, 432)` => `432`
`min(a,b)`
---
Returns the smallest of `a` and `b`.
- `bigInt.min(77, 432)` => `77`
`minus(number)`

@@ -197,2 +243,8 @@ ---

`modPow(exp, mod)`
---
Takes the number to the power `exp` modulo `mod`.
- `bigInt(10).modPow(3, 30)` => `10`
`multiply(number)`

@@ -243,2 +295,8 @@ ---

`square()`
---
Squares the number
- `bigInt(3).square()` => `9`
`subtract(number)`

@@ -250,2 +308,8 @@ ---

`randBetween(min, max)`
---
Returns a random number between `min` and `max`.
- `bigInt.randBetween("-1e100", "1e100")` => (for example) `8494907165436643479673097939554427056789510374838494147955756275846226209006506706784609314471378745`
`remainder(number)`

@@ -252,0 +316,0 @@ ---

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