You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
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

Comparing version 1.4.1 to 1.4.3

.travis.yml

55

BigInteger.js
"use strict";
var bigInt = (function () {
var base = 10000000, logBase = 7;
var base = 10000000, logBase = 7, zeros = "0000000";
var sign = {

@@ -149,36 +149,16 @@ positive: false,

var a = this.value, b = n.value;
var length = Math.max(a.length, b.length);
var resultSum = [];
for (var i = 0; i < length; i++) {
resultSum[i] = [];
var j = i;
while (j--) {
resultSum[i].push(0);
}
var result = [];
for (var i = a.length + b.length; i > 0; i--) {
result.push(0);
}
var carry = 0;
for (var i = 0; i < a.length; i++) {
var x = a[i];
for (var j = 0; j < b.length || carry > 0; j++) {
for (var j = 0; j < b.length; j++) {
var y = b[j];
var product = y ? (x * y) + carry : carry;
carry = Math.floor(product / base);
resultSum[i].push(product % base);
var product = x * y + result[i+j];
var q = Math.floor(product / base);
result[i+j] = product - q * base;
result[i+j+1] += q;
}
}
var max = -1;
for (var i = 0; i < resultSum.length; i++) {
var len = resultSum[i].length;
if (len > max) max = len;
}
var result = [], carry = 0;
for (var i = 0; i < max || carry > 0; i++) {
var sum = carry;
for (var j = 0; j < resultSum.length; j++) {
sum += resultSum[j][i] || 0;
}
carry = sum >= base ? Math.floor(sum / base) : 0;
sum -= carry * base;
result.push(sum);
}
return new BigInteger(trim(result), sign);

@@ -484,14 +464,11 @@ };

var str = "", len = first.value.length;
if (len === 0) {
if (len === 0 || (len === 1 && first.value[0] === 0)) {
return "0";
}
while (len--) {
if (first.value[len].toString().length === 8) str += first.value[len];
else str += (base.toString() + first.value[len]).slice(-logBase);
len -= 1;
str = first.value[len].toString();
while (--len >= 0) {
var digit = first.value[len].toString();
str += zeros.slice(digit.length) + digit;
}
while (str[0] === "0") {
str = str.slice(1);
}
if (!str.length) str = "0";
if (str === "0") return str;
var s = first.sign === sign.positive ? "" : "-";

@@ -575,3 +552,3 @@ return s + str;

}
return new BigInteger(value, s);
return new BigInteger(trim(value), s);
}

@@ -578,0 +555,0 @@

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

"use strict";var bigInt=function(){function r(e,t){this.value=e,this.sign=t}function i(e){var t=e.length-1;while(e[t]===0&&t>0)t--;return e.slice(0,t+1)}function s(t,n){var i=n<0;if(t.sign!==i)return i?o(t.abs(),-n):o(t.abs(),n).negate();i&&(n=-n);var s=t.value,u=[],a=0;for(var f=0;f<s.length||a>0;f++){var l=(s[f]||0)+(f>0?0:n)+a;a=l>=e?1:0,u.push(l%e)}return new r(u,t.sign)}function o(t,n){if(t.sign!==n<0)return s(t,-n);var i=!1;t.sign&&(i=!0);var o=t.value;if(o.length===1&&o[0]<n)return new r([n-o[0]],!i);i&&(n=-n);var u=[],a=0;for(var f=0;f<o.length;f++){var l=o[f]-a-(f>0?0:n);a=l<0?1:0,u.push(a*e+l)}return new r(u,i)}function u(t,n){var i=t.value,s=n<0,o=[],u=0;s&&(n=-n);for(var a=0;a<i.length||u>0;a++){var f=(i[a]||0)*n+u;u=f/e|0,o.push(f%e)}return new r(o,s?!t.sign:t.sign)}function a(t,n){if(n===0)throw new Error("Cannot divide by zero.");var s=t.value,o=n<0,u=[],a=0;o&&(n=-n);for(var f=s.length-1;f>=0;f--){var l=a*e+s[f];a=l%n,u.push(l/n|0)}return{quotient:new r(i(u.reverse()),o?!t.sign:t.sign),remainder:new r([a],t.sign)}}function f(t){return(typeof t=="number"||typeof t=="string")&&+t<=e||t instanceof r&&t.value.length<=1}function l(e,t){return e=x(e).abs(),t=x(t).abs(),e.equals(t)?e:e.equals(w)?t:t.equals(w)?e:e.isEven()?t.isOdd()?l(e.divide(2),t):l(e.divide(2),t.divide(2)).multiply(2):t.isEven()?l(e,t.divide(2)):e.greater(t)?l(e.subtract(t).divide(2),t):l(t.subtract(e).divide(2),e)}function c(e,t){return e=x(e).abs(),t=x(t).abs(),e.multiply(t).divide(l(e,t))}function h(e,t){return e=x(e),t=x(t),e.greater(t)?e:t}function p(e,t){return e=x(e),t=x(t),e.lesser(t)?e:t}function d(t,n){t=x(t),n=x(n);var i=p(t,n),s=h(t,n),o=s.subtract(i),u=o.value.length-1,a=[],f=!0;for(var l=u;l>=0;l--){var c=f?o.value[l]:e,d=Math.floor(Math.random()*c);a.unshift(d),d<c&&(f=!1)}return i.add(new r(a,!1))}function y(e,t,n){var r=w,i=h(e.abs(),t.abs()),s=0,o=E;while(o.lesserOrEquals(i)){var a,f;a=e.over(o).isEven()?0:1,f=t.over(o).isEven()?0:1,r=r.add(o.times(n(a,f))),o=u(o,2)}return r}function x(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=x(u);var a=i[0].indexOf(".");a>=0&&(u=u.minus(i[0].length-a),i[0]=i[0].slice(0,a)+i[0].slice(a+1));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: "+i);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)}function N(e){var t=e.value;return t.length===1&&t[0]<=36?"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t[0]):"<"+t+">"}function C(e,t){t=bigInt(t);if(t.equals(0)){if(e.equals(0))return"0";throw new Error("Cannot convert nonzero numbers to base 0.")}if(t.equals(-1))return e.equals(0)?"0":e.lesser(0)?Array(1-e).join("10"):"1"+Array(+e).join("01");var n="";e.isNegative()&&t.isPositive()&&(n="-",e=e.abs());if(t.equals(1))return e.equals(0)?"0":n+Array(+e+1).join(1);var r=[],i=e,s;while(i.lesser(0)||i.compareAbs(t)>=0){s=i.divmod(t),i=s.quotient;var o=s.remainder;o.lesser(0)&&(o=t.minus(o).abs(),i=i.next()),r.push(N(o))}return r.push(N(i)),n+r.reverse().join("")}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){if(f(t))return s(this,+t);t=x(t);if(this.sign!==t.sign)return this.sign===n.positive?this.abs().subtract(t.abs()):t.abs().subtract(this.abs());var o=this.value,u=t.value,a=[],l=0,c=Math.max(o.length,u.length);for(var h=0;h<c||l>0;h++){var p=(o[h]||0)+(u[h]||0)+l;l=p>=e?1:0,a.push(p%e)}return new r(i(a),this.sign)},r.prototype.plus=function(e){return this.add(e)},r.prototype.subtract=function(t){if(f(t))return o(this,+t);t=x(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,u=t.value,a=[],l=0,c=Math.max(s.length,u.length);for(var h=0;h<c;h++){var p=s[h]||0,d=u[h]||0,v=p-l;l=v<d?1:0,a.push(l*e+v-d)}return new r(i(a),n.positive)},r.prototype.minus=function(e){return this.subtract(e)},r.prototype.multiply=function(t){if(f(t))return u(this,+t);t=x(t);var n=this.sign!==t.sign,s=this.value,o=t.value,a=Math.max(s.length,o.length),l=[];for(var c=0;c<a;c++){l[c]=[];var h=c;while(h--)l[c].push(0)}var p=0;for(var c=0;c<s.length;c++){var d=s[c];for(var h=0;h<o.length||p>0;h++){var v=o[h],m=v?d*v+p:p;p=Math.floor(m/e),l[c].push(m%e)}}var g=-1;for(var c=0;c<l.length;c++){var y=l[c].length;y>g&&(g=y)}var b=[],p=0;for(var c=0;c<g||p>0;c++){var w=p;for(var h=0;h<l.length;h++)w+=l[h][c]||0;p=w>=e?Math.floor(w/e):0,w-=p*e,b.push(w)}return new r(i(b),n)},r.prototype.times=function(e){return this.multiply(e)},r.prototype.divmod=function(e){if(f(e))return a(this,+e);e=x(e);var t=this.sign!==e.sign;if(this.equals(0))return{quotient:new r([0],n.positive),remainder:new r([0],n.positive)};if(e.equals(0))throw new Error("Cannot divide by zero");var s=this.value,o=e.value,u=[],l=[];for(var c=s.length-1;c>=0;c--){var h=[s[c]].concat(l),p=b(o,h);u.push(p.result),l=p.remainder}return u.reverse(),{quotient:new r(i(u),t),remainder:new r(i(l),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=x(e);var t=this,n=e,r=E;if(n.equals(w))return r;if(t.equals(w)||n.lesser(w))return w;for(;;){n.isOdd()&&(r=r.times(t)),n=n.divide(2);if(n.equals(w))break;t=t.times(t)}return r},r.prototype.modPow=function(e,t){e=x(e),t=x(t);if(t.equals(w))throw new Error("Cannot take modPow with modulus 0");var n=E,r=this.mod(t);if(r.equals(w))return w;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 s(this,1)},r.prototype.prev=function(){return o(this,1)},r.prototype.compare=function(e){var t=this,r=x(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.lt=r.prototype.lesser,r.prototype.leq=r.prototype.lesserOrEquals,r.prototype.gt=r.prototype.greater,r.prototype.geq=r.prototype.greaterOrEquals,r.prototype.eq=r.prototype.equals,r.prototype.neq=r.prototype.notEquals,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(w)},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(E)||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};var v=[1];while(v[v.length-1]<=e)v.push(2*v[v.length-1]);var m=v.length,g=v[m-1];r.prototype.shiftLeft=function(e){if(!f(e))return e.isNegative()?this.shiftRight(e.abs()):this.times(bigInt(2).pow(e));e=+e;if(e<0)return this.shiftRight(-e);var t=this;while(e>=m)t=u(t,g),e-=m-1;return u(t,v[e])},r.prototype.shiftRight=function(e){if(!f(e))return e.isNegative()?this.shiftLeft(e.abs()):this.over(bigInt(2).pow(e));e=+e;if(e<0)return this.shiftLeft(-e);var t=this;while(e>=m){if(t.equals(w))return t;t=a(t,g).quotient,e-=m-1}return a(t,v[e]).quotient},r.prototype.not=function(){var e=y(this,this,function(e){return(e+1)%2});return this.sign?e:e.negate()},r.prototype.and=function(e){e=x(e);var t=y(this,e,function(e,t){return e*t});return this.sign&&e.sign?t.negate():t},r.prototype.or=function(e){e=x(e);var t=y(this,e,function(e,t){return(e+t+e*t)%2});return this.sign||e.sign?t.negate():t},r.prototype.xor=function(e){e=x(e);var t=y(this,e,function(e,t){return(e+t)%2});return this.sign^e.sign?t.negate():t},r.prototype.toString=function(r){r===undefined&&(r=10);if(r!==10)return C(this,r);var i=this,s="",o=i.value.length;if(o===0)return"0";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.valueOf()},r.prototype.valueOf=function(){return this.value.length===1?this.sign?-this.value[0]:this.value[0]:+this.toString()};var b=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}},w=new r([0],n.positive),E=new r([1],n.positive),S=new r([1],n.negative),T=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(x(t));else if(/[a-z]/.test(t))r.push(x(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(x(e.slice(n+1,i)))}}t=x(t);var n=w,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},k=function(e,t){return typeof e=="undefined"?w:typeof t!="undefined"?T(e,t):x(e)};return k.zero=w,k.one=E,k.minusOne=S,k.randBetween=d,k.min=p,k.max=h,k.gcd=l,k.lcm=c,k}();typeof module!="undefined"&&(module.exports=bigInt);
"use strict";var bigInt=function(){function i(e,t){this.value=e,this.sign=t}function s(e){while(e[e.length-1]===0&&e.length>1)e.pop();return e}function o(t,n){var r=n<0;if(t.sign!==r)return r?u(t.abs(),-n):u(t.abs(),n).negate();r&&(n=-n);var o=t.value,a=[],f=0;for(var l=0;l<o.length||f>0;l++){var c=(o[l]||0)+(l>0?0:n)+f;f=c>=e?1:0,a.push(c%e)}return new i(s(a),t.sign)}function u(t,n){var r=t.value;if(r.length===1)return r=r[0],t.sign&&(r=-r),new i([Math.abs(r-n)],r-n<0);if(t.sign!==n<0)return o(t,-n);var u=!1;t.sign&&(u=!0);if(r.length===1&&r[0]<n)return new i([n-r[0]],!u);u&&(n=-n);var a=[],f=0;for(var l=0;l<r.length;l++){var c=r[l]-f-(l>0?0:n);f=c<0?1:0,a.push(f*e+c)}return new i(s(a),u)}function a(t,n){var r=t.value,o=n<0,u=[],a=0;o&&(n=-n);for(var f=0;f<r.length||a>0;f++){var l=(r[f]||0)*n+a;a=l/e|0,u.push(l%e)}return new i(s(u),o?!t.sign:t.sign)}function f(t,n){if(n===0)throw new Error("Cannot divide by zero.");var r=t.value,o=n<0,u=[],a=0;o&&(n=-n);for(var f=r.length-1;f>=0;f--){var l=a*e+r[f];a=l%n,u.push(l/n|0)}return{quotient:new i(s(u.reverse()),o?!t.sign:t.sign),remainder:new i([a],t.sign)}}function l(t){return(typeof t=="number"||typeof t=="string")&&+Math.abs(t)<=e||t instanceof i&&t.value.length<=1}function c(e,t){return e=T(e).abs(),t=T(t).abs(),e.equals(t)?e:e.equals(E)?t:t.equals(E)?e:e.isEven()?t.isOdd()?c(e.divide(2),t):c(e.divide(2),t.divide(2)).multiply(2):t.isEven()?c(e,t.divide(2)):e.greater(t)?c(e.subtract(t).divide(2),t):c(t.subtract(e).divide(2),e)}function h(e,t){return e=T(e).abs(),t=T(t).abs(),e.multiply(t).divide(c(e,t))}function p(e,t){return e=T(e),t=T(t),e.greater(t)?e:t}function d(e,t){return e=T(e),t=T(t),e.lesser(t)?e:t}function v(t,n){t=T(t),n=T(n);var r=d(t,n),s=p(t,n),o=s.subtract(r),u=o.value.length-1,a=[],f=!0;for(var l=u;l>=0;l--){var c=f?o.value[l]:e,h=Math.floor(Math.random()*c);a.unshift(h),h<c&&(f=!1)}return r.add(new i(a,!1))}function b(e,t,n){var r=E,i=p(e.abs(),t.abs()),s=0,o=S;while(o.lesserOrEquals(i)){var u,f;u=e.over(o).isEven()?0:1,f=t.over(o).isEven()?0:1,r=r.add(o.times(n(u,f))),o=a(o,2)}return r}function T(n){if(n instanceof i)return n;if(Math.abs(+n)<e&&+n===(+n|0)){var o=+n;return new i([Math.abs(o)],o<0||1/o===-Infinity)}n+="";var u=r.positive,o=[];n[0]==="-"&&(u=r.negative,n=n.slice(1));var n=n.split(/e/i);if(n.length>2)throw new Error("Invalid integer: "+n.join("e"));if(n[1]){var a=n[1];a[0]==="+"&&(a=a.slice(1)),a=T(a);var f=n[0].indexOf(".");f>=0&&(a=a.minus(n[0].length-f),n[0]=n[0].slice(0,f)+n[0].slice(f+1));if(a.lesser(0))throw new Error("Cannot include negative exponent part for integers");while(a.notEquals(0))n[0]+="0",a=a.prev()}n=n[0],n==="-0"&&(n="0");var l=/^([0-9][0-9]*)$/.test(n);if(!l)throw new Error("Invalid integer: "+n);while(n.length){var c=n.length>t?n.length-t:0;o.push(+n.slice(c)),n=n.slice(0,c)}return new i(s(o),u)}function C(e){var t=e.value;return t.length===1&&t[0]<=36?"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t[0]):"<"+t+">"}function k(e,t){t=bigInt(t);if(t.equals(0)){if(e.equals(0))return"0";throw new Error("Cannot convert nonzero numbers to base 0.")}if(t.equals(-1))return e.equals(0)?"0":e.lesser(0)?Array(1-e).join("10"):"1"+Array(+e).join("01");var n="";e.isNegative()&&t.isPositive()&&(n="-",e=e.abs());if(t.equals(1))return e.equals(0)?"0":n+Array(+e+1).join(1);var r=[],i=e,s;while(i.lesser(0)||i.compareAbs(t)>=0){s=i.divmod(t),i=s.quotient;var o=s.remainder;o.lesser(0)&&(o=t.minus(o).abs(),i=i.next()),r.push(C(o))}return r.push(C(i)),n+r.reverse().join("")}var e=1e7,t=7,n="0000000",r={positive:!1,negative:!0};i.prototype.negate=function(){return new i(this.value,!this.sign)},i.prototype.abs=function(){return new i(this.value,r.positive)},i.prototype.add=function(t){if(l(t))return o(this,+t);t=T(t);if(this.sign!==t.sign)return this.sign===r.positive?this.abs().subtract(t.abs()):t.abs().subtract(this.abs());var n=this.value,u=t.value,a=[],f=0,c=Math.max(n.length,u.length);for(var h=0;h<c||f>0;h++){var p=(n[h]||0)+(u[h]||0)+f;f=p>=e?1:0,a.push(p%e)}return new i(s(a),this.sign)},i.prototype.plus=i.prototype.add,i.prototype.subtract=function(t){if(l(t))return u(this,+t);t=T(t);if(this.sign!==t.sign)return this.add(t.negate());if(this.sign===r.negative)return t.negate().subtract(this.negate());if(this.compare(t)<0)return t.subtract(this).negate();var n=this.value,o=t.value,a=[],f=0,c=Math.max(n.length,o.length);for(var h=0;h<c;h++){var p=n[h]||0,d=o[h]||0,v=p-f;f=v<d?1:0,a.push(f*e+v-d)}return new i(s(a),r.positive)},i.prototype.minus=i.prototype.subtract,i.prototype.multiply=function(t){if(l(t))return a(this,+t);t=T(t);var n=this.sign!==t.sign,r=this.value,o=t.value,u=[];for(var f=r.length+o.length;f>0;f--)u.push(0);for(var f=0;f<r.length;f++){var c=r[f];for(var h=0;h<o.length;h++){var p=o[h],d=c*p+u[f+h],v=Math.floor(d/e);u[f+h]=d-v*e,u[f+h+1]+=v}}return new i(s(u),n)},i.prototype.times=i.prototype.multiply,i.prototype.divmod=function(e){if(l(e))return f(this,+e);e=T(e);var t=this.sign!==e.sign;if(this.equals(0))return{quotient:new i([0],r.positive),remainder:new i([0],r.positive)};if(e.equals(0))throw new Error("Cannot divide by zero");var n=this.value,o=e.value,u=[],a=[];for(var c=n.length-1;c>=0;c--){var h=[n[c]].concat(a),p=w(o,h);u.push(p.result),a=p.remainder}return u.reverse(),{quotient:new i(s(u),t),remainder:new i(s(a),this.sign)}},i.prototype.divide=function(e){return this.divmod(e).quotient},i.prototype.over=i.prototype.divide,i.prototype.mod=function(e){return this.divmod(e).remainder},i.prototype.remainder=i.prototype.mod,i.prototype.pow=function(e){e=T(e);var t=this,n=e,r=S;if(n.equals(E))return r;if(t.equals(E)||n.lesser(E))return E;for(;;){n.isOdd()&&(r=r.times(t)),n=n.divide(2);if(n.equals(E))break;t=t.times(t)}return r},i.prototype.modPow=function(e,t){e=T(e),t=T(t);if(t.equals(E))throw new Error("Cannot take modPow with modulus 0");var n=S,r=this.mod(t);if(r.equals(E))return E;while(e.greater(0))e.isOdd()&&(n=n.multiply(r).mod(t)),e=e.divide(2),r=r.square().mod(t);return n},i.prototype.square=function(){return this.multiply(this)},i.prototype.next=function(){return o(this,1)},i.prototype.prev=function(){return u(this,1)},i.prototype.compare=function(e){var t=this,n=T(e);if(t.value.length===1&&n.value.length===1&&t.value[0]===0&&n.value[0]===0)return 0;if(n.sign!==t.sign)return t.sign===r.positive?1:-1;var i=t.sign===r.positive?1:-1,s=t.value,o=n.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},i.prototype.compareAbs=function(e){return this.abs().compare(e.abs())},i.prototype.equals=function(e){return this.compare(e)===0},i.prototype.notEquals=function(e){return!this.equals(e)},i.prototype.lesser=function(e){return this.compare(e)<0},i.prototype.greater=function(e){return this.compare(e)>0},i.prototype.greaterOrEquals=function(e){return this.compare(e)>=0},i.prototype.lesserOrEquals=function(e){return this.compare(e)<=0},i.prototype.compareTo=i.prototype.compare,i.prototype.lt=i.prototype.lesser,i.prototype.leq=i.prototype.lesserOrEquals,i.prototype.gt=i.prototype.greater,i.prototype.geq=i.prototype.greaterOrEquals,i.prototype.eq=i.prototype.equals,i.prototype.neq=i.prototype.notEquals,i.prototype.isPositive=function(){return this.value.length===1&&this.value[0]===0?!1:this.sign===r.positive},i.prototype.isNegative=function(){return this.value.length===1&&this.value[0]===0?!1:this.sign===r.negative},i.prototype.isEven=function(){return this.value[0]%2===0},i.prototype.isOdd=function(){return this.value[0]%2===1},i.prototype.isUnit=function(){return this.value.length===1&&this.value[0]===1},i.prototype.isZero=function(){return this.value.length===1&&this.value[0]===0},i.prototype.isDivisibleBy=function(e){return e=T(e),e.isZero()?!1:this.mod(e).equals(E)},i.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(S)||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};var m=[1];while(m[m.length-1]<=e)m.push(2*m[m.length-1]);var g=m.length,y=m[g-1];i.prototype.shiftLeft=function(e){if(!l(e))return e.isNegative()?this.shiftRight(e.abs()):this.times(bigInt(2).pow(e));e=+e;if(e<0)return this.shiftRight(-e);var t=this;while(e>=g)t=a(t,y),e-=g-1;return a(t,m[e])},i.prototype.shiftRight=function(e){if(!l(e))return e.isNegative()?this.shiftLeft(e.abs()):this.over(bigInt(2).pow(e));e=+e;if(e<0)return this.shiftLeft(-e);var t=this;while(e>=g){if(t.equals(E))return t;t=f(t,y).quotient,e-=g-1}return f(t,m[e]).quotient},i.prototype.not=function(){var e=b(this,this,function(e){return(e+1)%2});return this.sign?e:e.negate()},i.prototype.and=function(e){e=T(e);var t=b(this,e,function(e,t){return e*t});return this.sign&&e.sign?t.negate():t},i.prototype.or=function(e){e=T(e);var t=b(this,e,function(e,t){return(e+t+e*t)%2});return this.sign||e.sign?t.negate():t},i.prototype.xor=function(e){e=T(e);var t=b(this,e,function(e,t){return(e+t)%2});return this.sign^e.sign?t.negate():t},i.prototype.toString=function(e){e===undefined&&(e=10);if(e!==10)return k(this,e);var t=this,i="",s=t.value.length;if(s===0||s===1&&t.value[0]===0)return"0";s-=1,i=t.value[s].toString();while(--s>=0){var o=t.value[s].toString();i+=n.slice(o.length)+o}var u=t.sign===r.positive?"":"-";return u+i},i.prototype.toJSNumber=function(){return this.valueOf()},i.prototype.valueOf=function(){return this.value.length===1?this.sign?-this.value[0]:this.value[0]:+this.toString()};var w=function(e,t){var e=new i(e,r.positive),t=new i(t,r.positive);if(e.equals(0))throw new Error("Cannot divide by 0");var n=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),n+=s}while(e.lesserOrEquals(t));return{remainder:t.value,result:n}},E=new i([0],r.positive),S=new i([1],r.positive),x=new i([1],r.negative),N=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(T(t));else if(/[a-z]/.test(t))r.push(T(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(T(e.slice(n+1,i)))}}t=T(t);var n=E,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},L=function(e,t){return typeof e=="undefined"?E:typeof t!="undefined"?N(e,t):T(e)};return L.zero=E,L.one=S,L.minusOne=x,L.randBetween=v,L.min=d,L.max=p,L.gcd=c,L.lcm=h,L}();typeof module!="undefined"&&(module.exports=bigInt);
{
"name": "big-integer",
"version": "1.4.1",
"version": "1.4.3",
"author": "Peter Olson <peter.e.c.olson+npm@gmail.com>",

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

"bin": {},
"scripts": {},
"scripts": {
"test": "jasmine"
},
"main": "./BigInteger",

@@ -26,3 +28,5 @@ "repository": {

],
"dependencies" : {},
"dependencies" : {
"jasmine": "2.1.x"
},
"license": "WTFPL",

@@ -29,0 +33,0 @@ "engines": {

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

[![Build Status](https://travis-ci.org/peterolson/BigInteger.js.svg?branch=master)](https://travis-ci.org/peterolson/BigInteger.js)
BigInteger.js

@@ -2,0 +4,0 @@ =========

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc