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.3.18 to 1.3.19

5

BigInteger.js

@@ -548,2 +548,7 @@ "use strict";

exp = parseInput(exp);
var decimalPlace = text[0].indexOf(".");
if (decimalPlace >= 0) {
exp = exp.minus(text[0].length - decimalPlace);
text[0] = text[0].slice(0, decimalPlace) + text[0].slice(decimalPlace + 1);
}
if (exp.lesser(0)) throw new Error("Cannot include negative exponent part for integers");

@@ -550,0 +555,0 @@ while (exp.notEquals(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 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);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)}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 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);

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

"256 in base 1 has 256 ones": bigInt(256).toString(1).length === 256,
"1.34e2 == 134": bigInt("1.34e2").equals(134),
"1.7976931348623157e+308": bigInt("1.7976931348623157e+308").equals("17976931348623157000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
// Bit operations

@@ -154,0 +156,0 @@ "1024 << 100 = 1298074214633706907132624082305024": bigInt(1024).shiftLeft(100).equals("1298074214633706907132624082305024"),

{
"name": "big-integer",
"version": "1.3.18",
"version": "1.3.19",
"author": "Peter Olson <peter.e.c.olson+npm@gmail.com>",

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

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